Project

General

Profile

Actions

Bug #4683

closed

[PATCH] io.c: copy_stream execute interrupts and retry

Added by normalperson (Eric Wong) almost 13 years ago. Updated almost 13 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 1.9.3dev (2011-05-13 trunk 31504) [x86_64-linux]
Backport:
[ruby-core:36156]

Description

It's debatable whether this is a bug or not, but I think the current interrupt
handling behavior with IO.copy_stream is fragile and unpredictable, and
inconsistent with IO#read and IO#write.

This is to be consistent with IO#read and IO#write behavior
where rb_io_wait_readable() and rb_io_wait_writable() retry
on interrupt (EAGAIN/ERESTART) instead of returning a short
copy or raising Errno::EINTR.


Files

0001-io.c-copy_stream-execute-interrupts-and-retry.patch (4.02 KB) 0001-io.c-copy_stream-execute-interrupts-and-retry.patch patch to fix the issue normalperson (Eric Wong), 05/13/2011 06:56 AM
0002-test_io-add-test-for-copy_stream-failing-on-EINTR.patch (1.75 KB) 0002-test_io-add-test-for-copy_stream-failing-on-EINTR.patch test case, may not be portable... normalperson (Eric Wong), 05/13/2011 06:56 AM
copy_stream_interrupt_handling.patch (7.97 KB) copy_stream_interrupt_handling.patch akr (Akira Tanaka), 05/29/2011 07:29 PM
copy_stream_interrupt_handling-2.patch (9.42 KB) copy_stream_interrupt_handling-2.patch akr (Akira Tanaka), 06/02/2011 08:20 PM

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #4680: [PATCH] io.c: fix busy wait with sendfile()Closedakr (Akira Tanaka)05/13/2011Actions

Updated by normalperson (Eric Wong) almost 13 years ago

Eric Wong wrote:

Bug #4683: [PATCH] io.c: copy_stream execute interrupts and retry
http://redmine.ruby-lang.org/issues/4683

It's debatable whether this is a bug or not, but I think the current interrupt
handling behavior with IO.copy_stream is fragile and unpredictable, and
inconsistent with IO#read and IO#write.

This is to be consistent with IO#read and IO#write behavior
where rb_io_wait_readable() and rb_io_wait_writable() retry
on interrupt (EAGAIN/ERESTART) instead of returning a short
copy or raising Errno::EINTR.

Can I get a response on this soon? I really want this issue resolved
before 1.9.3 because it's inconsistent with existing Ruby read/write
behavior and working around it painful.

A backport to 1.9.2 would be appreciated, too.

Thanks!

--
Eric Wong

Updated by naruse (Yui NARUSE) almost 13 years ago

  • Status changed from Open to Assigned
  • Assignee set to akr (Akira Tanaka)

Updated by akr (Akira Tanaka) almost 13 years ago

I think this is subtle but interesting issue. Thank you.

I'm not sure rb_thread_interrupted() is callable without GVL.
kosaki pointed mutual exclusion issue with interrupt_flag.
http://redmine.ruby-lang.org/issues/4770

Since the experimental function rb_thread_call_with_gvl is not callable
with GVL, nogvl_copy_stream_continue_p is not callable with GVL.
So nogvl_copy_stream_continue_p is not callable from maygvl_* such as
maygvl_copy_stream_wait_read.
I guess maygvl_* functions needs has_gvl parameter to keep GVL status.

Updated by akr (Akira Tanaka) almost 13 years ago

Hm. rb_thread_interrupted() is safe to call from blocking region.

Updated by akr (Akira Tanaka) almost 13 years ago

As far as I remember, io.c should not use vm_core.h and rb_thread_t.
ko1 dislikes it.

Updated by normalperson (Eric Wong) almost 13 years ago

Akira Tanaka wrote:

As far as I remember, io.c should not use vm_core.h and rb_thread_t.
ko1 dislikes it.

I think we can work around it by making more API methods public.

I have an old issue open to export rb_thread_call_with_gvl() for
extensions:
http://redmine.ruby-lang.org/issues/4328

Perhaps exec_interrupts() can be made into a public API method:
rb_thread_exec_interrupts_with_gvl()

--
Eric Wong

Updated by akr (Akira Tanaka) almost 13 years ago

Adding public functions needs a discussion with ko1.

copy_stream_interrupt_handling-2.patch uses internal.h to share
declarations between io.c and thread.c.

Updated by normalperson (Eric Wong) almost 13 years ago

Akira Tanaka wrote:

Issue #4683 has been updated by Akira Tanaka.

File copy_stream_interrupt_handling-2.patch added

Patch looks good, thanks! Can you please commit?

Adding public functions needs a discussion with ko1.

I haven't seen any response for #4328 in months, though :(

--
Eric Wong

Updated by akr (Akira Tanaka) almost 13 years ago

  • Status changed from Assigned to Closed
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0Like0