Issue #14571 has been updated by nobu (Nobuyoshi Nakada).


Just to clarify, do those file descriptors get closed by GC?

----------------------------------------
Bug #14571: File descriptor leak in resolv.rb
https://bugs.ruby-lang.org/issues/14571#change-70801

* Author: quixoten (Devin Christensen)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
There's an edge case in resolv.rb that can lead to file descriptor leaks on a highly saturated system (logstash in our case).

![file-descriptor-leak](https://user-images.githubusercontent.com/63675/36873892-3507d282-1d67-11e8-9912-3ba58a287b5b.png)

(the cliff at the end is from a restart of the application)

We're using the logstash-filter-dns plugin which [uses timeout](https://github.com/logstash-plugins/logstash-filter-dns/blob/v3.0.7/lib/logstash/filters/dns.rb#L250-L252).

When a timeout fires while [waiting](https://github.com/ruby/ruby/blob/8032b00f8e43be6e34f93005a17e26bc6d89f1c1/lib/resolv.rb#L649-L658) for a [random](https://github.com/ruby/ruby/blob/8032b00f8e43be6e34f93005a17e26bc6d89f1c1/lib/resolv.rb#L752) [port](https://github.com/ruby/ruby/blob/8032b00f8e43be6e34f93005a17e26bc6d89f1c1/lib/resolv.rb#L805), the new object is never returned to the caller. Instead `requester` is [set to nil](https://github.com/ruby/ruby/blob/8032b00f8e43be6e34f93005a17e26bc6d89f1c1/lib/resolv.rb#L514). There's no handle to any sockets that were created in the initializer, so they can't be closed, and one ore more file descriptors is leaked.


(This if my first patch submission, let me know what I can fix or do better.)

---Files--------------------------------
add-failing-tests.patch (1.39 KB)
fix-leak.patch (5.01 KB)
combined.patch (6.4 KB)


-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>