Project

General

Profile

Actions

Bug #14571

closed

File descriptor leak in resolv.rb

Added by quixoten (Devin Christensen) about 6 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:85901]

Description

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

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

We're using the logstash-filter-dns plugin which uses timeout.

When a timeout fires while waiting for a random port, the new object is never returned to the caller. Instead requester is set to nil. 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) add-failing-tests.patch quixoten (Devin Christensen), 03/02/2018 07:09 PM
fix-leak.patch (5.01 KB) fix-leak.patch quixoten (Devin Christensen), 03/02/2018 07:09 PM
combined.patch (6.4 KB) combined.patch The two patches above combined. quixoten (Devin Christensen), 03/02/2018 07:09 PM

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

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

Actions #2

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Backport changed from 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
Actions #3

Updated by nobu (Nobuyoshi Nakada) about 6 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r62671.


resolv.rb: close socket

  • lib/resolv.rb (UnconnectedUDP#lazy_initialize): store new
    sockets before binding, so the sockets get closed when the
    requester is closing.

  • lib/resolv.rb (ConnectedUDP#lazy_initialize): ditto.

  • lib/resolv.rb (UnconnectedUDP#close): synchronize to get rid of
    race condition.

  • lib/resolv.rb (ConnectedUDP#close): ditto.

[ruby-core:85901] [Bug #14571]

From: quixoten (Devin Christensen)

Updated by nagachika (Tomoyuki Chikanaga) about 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r62915 merged revision(s) 62671.

Updated by usa (Usaku NAKAMURA) about 6 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_3 r62949 merged revision(s) 62671.

Actions #6

Updated by naruse (Yui NARUSE) over 5 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: DONE, 2.4: DONE to 2.3: DONE, 2.4: DONE, 2.5: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) about 5 years ago

  • Backport changed from 2.3: DONE, 2.4: DONE, 2.5: REQUIRED to 2.3: DONE, 2.4: DONE, 2.5: DONE

ruby_2_5 r66748 merged revision(s) 62671.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0