Project

General

Profile

Actions

Bug #9036

closed

[PATCH] io.c: make IO#reopen("pathname") atomic for non-stdio

Added by normalperson (Eric Wong) over 10 years ago. Updated over 9 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.1.0dev (2013-10-20 trunk 43369) [x86_64-linux]
[ruby-core:57943]

Description

Since rb_sysopen releases the GVL, calling close(fptr->fd) would
leave a window where accessing the file from another thread can hit
IOError on a closed stream

Instead, create a new, temporary FD via rb_sysopen and call
rb_cloexec_dup2 on it to atomically replace the file fptr->fd points
to. This leaves no possible window where fptr->fd is invalid to
userspace (even for any threads running w/o GVL).

Without this patch, I need to maintain separate code paths for
atomically reopening (e.g. log rotation) std{in,out,err} vs
other files in a multithreaded application.


Files

0001-io.c-make-IO-reopen-pathname-atomic.patch (1.47 KB) 0001-io.c-make-IO-reopen-pathname-atomic.patch [PATCH] io.c: make IO#reopen("pathname") atomic normalperson (Eric Wong), 10/20/2013 01:16 PM

Updated by normalperson (Eric Wong) over 10 years ago

"normalperson (Eric Wong)" wrote:

Without this patch, I need to maintain separate code paths for
atomically reopening (e.g. log rotation) std{in,out,err} vs
other files in a multithreaded application.

Separate code paths like this:
http://bogomips.org/yahns.git/patch/?id=bcb10abe5
(review greatly appreciated!, thanks!)

Actions #2

Updated by nobu (Nobuyoshi Nakada) over 10 years ago

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

This issue was solved with changeset r43373.
Eric, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


io.c: make IO#reopen("pathname") atomic

  • io.c (rb_io_reopen): create a new, temporary FD via rb_sysopen and
    call rb_cloexec_dup2 on it to atomically replace the file fptr->fd
    points to. This leaves no possible window where fptr->fd is invalid
    to userspace (even for any threads running w/o GVL). based on the
    patch by Eric Wong at [ruby-core:57943].
    [Bug #9036]

Updated by naruse (Yui NARUSE) over 9 years ago

  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED

Updated by nagachika (Tomoyuki Chikanaga) over 9 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: REQUIRED to 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: DONTNEED

r43373 was already included in ruby_2.1.

Updated by usa (Usaku NAKAMURA) over 9 years ago

  • Backport changed from 1.9.3: REQUIRED, 2.0.0: REQUIRED, 2.1: DONTNEED to 2.0.0: DONE, 2.1: DONTNEED

backported into ruby_2_0_0 at r47545.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0