KOSAKI Motohiro <kosaki.motohiro / gmail.com> wrote:
> > ----------------------------------------
> > Bug #4558: TestSocket#test_closed_read fails after r31230
> > http://redmine.ruby-lang.org/issues/4558
> 
> I think current rb_io_close() is broken. We have to call rb_thread_fd_close()
> before releasing GVL.
> 
> Eric, Am I missing something?

You are correct.

I can't reproduce the test failure on x86_64-linux but the
following patch should fix a race condition:

diff --git a/io.c b/io.c
index 7ce7148..b79cc5e 100644
--- a/io.c
+++ b/io.c
@@ -3685,8 +3685,8 @@ rb_io_close(VALUE io)
     if (fptr->fd < 0) return Qnil;
 
     fd = fptr->fd;
-    rb_io_fptr_cleanup(fptr, FALSE);
     rb_thread_fd_close(fd);
+    rb_io_fptr_cleanup(fptr, FALSE);
 
     if (fptr->pid) {
 	rb_syswait(fptr->pid);

-- 
Eric Wong