[ruby-cvs:70306] normal:r63216 (trunk): io.c: do not use rb_notify_fd_close close on recycled FD

normal at ruby-lang.org normal at ruby-lang.org
Sat Apr 21 12:12:36 JST 2018

normal	2018-04-21 12:12:36 +0900 (Sat, 21 Apr 2018)

  New Revision: 63216


    io.c: do not use rb_notify_fd_close close on recycled FD
    It is unsafe to release GVL and call rb_notify_fd_close after
    close(2) on any given FD.  FDs (file descriptor) may be recycled
    in other threads immediately after close() to point to a different
    file description.  Note the distinction between "file description"
    and "file descriptor".
    th-1                           | th-2
    io_close_fptr                  |
      rb_notify_fd_close(fd)       |
      fptr_finalize_flush          |
        close(fd)                  |
      rb_thread_schedule           |
                                   | fd reused (via pipe/open/socket/etc)
      rb_notify_fd_close(fd)       |
                                   | sees "stream closed" exception
           |   for DIFFERENT file description
    * thread.c (rb_thread_io_blocking_region): adjust comment for list_del
    * thread.c (rb_notify_fd_close): give busy list to caller
    * thread.c (rb_thread_fd_close): loop on busy list
    * io.c (io_close_fptr): do not call rb_thread_fd_close on invalid FD
    * io.c (io_reopen): use rb_thread_fd_close
    Fixes: r57422 ("io.c: close before wait")

  Modified files:

More information about the ruby-cvs mailing list