Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TCPSocket/UDPSocket close deadlock while other thread read #5081

Closed
yamam opened this issue Mar 6, 2018 · 3 comments
Closed

TCPSocket/UDPSocket close deadlock while other thread read #5081

yamam opened this issue Mar 6, 2018 · 3 comments

Comments

@yamam
Copy link

yamam commented Mar 6, 2018

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.

@headius
Copy link
Member

headius commented Mar 15, 2018

Fails to get to try 3 for me on jruby-9.1 HEAD.

@headius
Copy link
Member

headius commented Mar 15, 2018

Appears to run properly on master. I'm sure this is just more sync issues in the IO subsystem.

headius added a commit that referenced this issue Mar 15, 2018

Verified

This commit was signed with the committer’s verified signature.
headius Charles Oliver Nutter
@headius
Copy link
Member

headius commented Mar 15, 2018

After exploring diffs from master, I found the various commits where I improved concurrency had only been partially backported to 9.1.

71cae54 started it by trying to align some wait and select logic with CRuby.

dad9ab0 made additional improvements to locking.

e390180 fixed an additional race in closing a blocked IO.

I've cherry-picked the last item and aligned OpenFile.removeBlockingThread with master. Your example now runs properly on jruby-9.1 head.

Note that the fixes done on master were to address a hanging CRuby test, so there's currently no pressing need to write a new spec.

@headius headius closed this as completed Mar 15, 2018
@headius headius added this to the JRuby 9.1.17.0 milestone Mar 15, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants