Bug #8669
closedoutbuf can be "temporarily" locked forever in IO#read
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
Updated by normalperson (Eric Wong) over 11 years ago
"Glass_saga (Masaki Matsushita)" glass.saga@gmail.com 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
- File io_fread_callback.diff io_fread_callback.diff added
- File read_internal_callback.diff read_internal_callback.diff added
Furthermore, should we introduce a function to callback with locking temporarily?
I made rb_str_locktmp_ensure() to callback with locktmp.
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.