Project

General

Profile

Actions

Bug #4390

closed

TCPSocket#readline doesn't raise if the socket is #close'd in another thread

Added by regularfry (Alex Young) about 13 years ago. Updated almost 13 years ago.

Status:
Closed
Assignee:
-
Target version:
ruby -v:
ruby 1.9.2p136 (2010-12-25 revision 30365) [i686-linux]
Backport:
[ruby-core:35203]

Description

=begin
In Ruby 1.8.7-p302, the following code outputs "Success!". On 1.9.2-p136, it hangs at q.pop, because the blocked readline doesn't raise (or, more precisely, it does, I think, but the thread isn't woken up to process it).

require 'socket'
require 'thread'

server = TCPServer.new("localhost", 0)
serv_thread = Thread.new{ server.accept }
sleep(0.1)
sock = TCPSocket.new("localhost", server.addr[1])

q = Queue.new
client_thread = Thread.new{
begin
sock.readline
q.push "OK"
rescue StandardError => e
p e
q.push(e)
end
}

sleep(0.1) while client_thread.status == "run"
sock.close
err = q.pop
puts "Success!"

It's not immediately clear which is the correct behaviour, but I'm raising an issue against 1.9.2 on the principle that unless there was a conscious decision to change behaviour, a change indicates that something broke. I should also add that this behaviour is not observed in i386-cygwin.
=end


Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4558: TestSocket#test_closed_read fails after r31230Closedkosaki (Motohiro KOSAKI)04/07/2011Actions
Actions #1

Updated by nobu (Nobuyoshi Nakada) about 13 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

=begin
This issue was solved with changeset r30852.
Alex, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • thread.c (rb_thread_io_blocking_region): new function to run
    blocking region with GIL released, for fd.
  • thread.c (rb_thread_fd_close): implement. [ruby-core:35203]
    =end
Actions

Also available in: Atom PDF

Like0
Like0