Project

General

Profile

Actions

Bug #8669

closed

outbuf can be "temporarily" locked forever in IO#read

Added by Glass_saga (Masaki Matsushita) over 11 years ago. Updated over 11 years ago.

Status:
Closed
Target version:
ruby -v:
ruby 2.1.0dev (2013-07-23 trunk 42132) [x86_64-linux]
[ruby-core:56121]

Description

Following code make outbuf "temporarily" locked forever.
It is needed to ensure rb_str_unlocktmp().

str = ""
t = Thread.new(str) do |str|
r, = IO.pipe
r.read(nil, str)
end
sleep 1
t.raise
sleep 1
str.clear #=> can't modify string; temporarily locked (RuntimeError)

I have attached two patches.
One fixes io_fread(), another does io_getpartial() and rb_io_sysread().
May I commit these changes?


Files

io_fread.diff (984 Bytes) io_fread.diff for io_fread() Glass_saga (Masaki Matsushita), 07/23/2013 06:06 PM
read_internal.diff (1.85 KB) read_internal.diff for io_getpartial() and rb_io_sysread() Glass_saga (Masaki Matsushita), 07/23/2013 06:06 PM
io_fread_callback.diff (1.77 KB) io_fread_callback.diff for io_fread() with rb_str_locktmp_ensure() Glass_saga (Masaki Matsushita), 07/25/2013 01:59 PM
read_internal_callback.diff (2.7 KB) read_internal_callback.diff for io_getpartial() and rb_io_sysread() with rb_str_locktmp_ensure() Glass_saga (Masaki Matsushita), 07/25/2013 01:59 PM

Updated by normalperson (Eric Wong) over 11 years ago

"Glass_saga (Masaki Matsushita)" wrote:

Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN

I can confirm the issue under 1.9.3-p448 and 2.0.0-p247

Following code make outbuf "temporarily" locked forever.
It is needed to ensure rb_str_unlocktmp().

Nasty bug. I might've hit this soon in new project I'm working on(!)

I have attached two patches.
One fixes io_fread(), another does io_getpartial() and rb_io_sysread().
May I commit these changes?

Untested, but looks correct. Thanks.

Updated by nobu (Nobuyoshi Nakada) over 11 years ago

  • Status changed from Open to Assigned
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: REQUIRED, 2.0.0: REQUIRED

Seems fine.

Furthermore, should we introduce a function to callback with locking
temporarily?

Updated by Glass_saga (Masaki Matsushita) over 11 years ago

Furthermore, should we introduce a function to callback with locking temporarily?

I made rb_str_locktmp_ensure() to callback with locktmp.

Actions #4

Updated by Anonymous over 11 years ago

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

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


  • string.c: add internal API rb_str_locktmp_ensure().

  • io.c (io_fread): use rb_str_locktmp_ensure().
    [ruby-core:56121] [Bug #8669]

  • test/ruby/test_io.rb: add a test for above.

Updated by nagachika (Tomoyuki Chikanaga) over 11 years ago

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

Backported to ruby_2_0_0 at r42216.

Updated by usa (Usaku NAKAMURA) over 11 years ago

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

Backported to ruby_1_9_3 at r42327.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0