Thanks to visit codestin.com
Credit goes to github.com

Skip to content

FD leak with orphan Unix Socket #6529

@peacand

Description

@peacand

JRuby version
jruby 9.2.5.0 (2.5.0) 2018-12-06 6d5a228 OpenJDK 64-Bit Server VM 25.275-b01 on 1.8.0_275-8u275-b01-0ubuntu1~18.04-b01 +jit [linux-x86_64]

Env
Linux hostname01 4.15.0-112-generic #113-Ubuntu SMP Thu Jul 9 23:41:39 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Expected behavior

When trying to connect to a Unix Socket (UNIXSocket.new) on which no process is listening, an exception is raised and no file descriptor is left at the end of the connection attempt

Actual behavior

When trying to connect to a Unix Socket on which no process is listening, an IOError is raised and the socket file descriptor is not closed. Therefore, if a client keeps trying to connect to a crashed daemon supposed to listen on the Unix Socket, the JRuby client will also crashed due to file descriptors exhaustion because of the sockets not closed.

Example

require 'socket'

for i in 0..20
    begin
        a = UNIXSocket.new("uds.sock")
    rescue => e
        puts(e)
    end
end

gets

If the socket file uds.sock exists but no process it listening on it, the test script above will produce 20 IOError and at the end, if you look at the file descriptors you will see ~20 sockets.

Workaround

I did not find any way to workaround this issue. I had a look at the abstract namespace sockets also, which could be a way, but they don't seem to be implemented in JRuby 2.5.0 at least.

Could you help please ?

Thank you in advance

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions