Skip to content

TCPSocket/UDPSocket close deadlock while other thread read #5081

@yamam

Description

@yamam

Environment

jruby-9.1.16.0/bin/jruby.bash --version
jruby 9.1.16.0 (2.3.3) 2018-02-21 8f3f95a OpenJDK 64-Bit Server VM 25.151-b12 on 1.8.0_151-8u151-b12-0ubuntu0.16.04.2-b12 +jit [linux-x86_64]

Linux 4.4.0-116-generic #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

The minimal code for reproducing the issue follows:

udp.rb

require 'socket'
i = 0
while true
    puts "try #{i += 1}"

    sock = UDPSocket.new
    close_end_notify = Queue.new

    Thread.new do
        while close_end_notify.empty?
            begin
                puts "gets"
                sock.gets
                puts "gets end"
            rescue
                puts "exception #{$!}"
            end
        end
    end

    sleep 2
    puts "close"
    sock.close
    puts "close end"
    close_end_notify << nil

    sleep 2
    puts
end

Expected Behavior

Run udp.rb on jruby-9.1.15

try 1
gets
close
close end
exception stream closed

try 2
gets
close
close end
exception stream closed

try 3
gets
close
close endexception stream closed

gets
exception closed stream

try 4
gets
close
close end
exception stream closed

Actual Behavior

Run udp.rb on jruby-9.1.16

try 1
gets
close
exception stream closedclose end


try 2
gets
close
exception stream closed
getsclose end

exception closed stream

try 3
gets
close
exception stream closed
gets

In try3 close and gets didn't return.

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