Skip to content

Commit 59fb929

Browse files
author
normal
committed
IO#close: do not enqueue redundant interrupts
Enqueuing multiple errors for one event causes spurious errors down the line, as reported by Nikolay Vashchenko in https://bugs.ruby-lang.org/issues/13632 * thread.c (rb_notify_fd_close): do not enqueue multiple interrupts [ruby-core:81581] [Bug ruby#13632] * test/ruby/test_io.rb (test_single_exception_on_close): new test based on script from Nikolay git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59020 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
1 parent cb85a53 commit 59fb929

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

test/ruby/test_io.rb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2823,6 +2823,28 @@ def test_cross_thread_close_stdio
28232823
end;
28242824
end
28252825

2826+
def test_single_exception_on_close
2827+
a = []
2828+
t = []
2829+
10.times do
2830+
r, w = IO.pipe
2831+
a << [r, w]
2832+
t << Thread.new do
2833+
while r.gets
2834+
end rescue IOError
2835+
Thread.current.pending_interrupt?
2836+
end
2837+
end
2838+
a.each do |r, w|
2839+
w.write -"\n"
2840+
w.close
2841+
r.close
2842+
end
2843+
t.each do |th|
2844+
assert_equal false, th.value, '[ruby-core:81581] [Bug #13632]'
2845+
end
2846+
end
2847+
28262848
def test_open_mode
28272849
feature4742 = "[ruby-core:36338]"
28282850
bug6055 = '[ruby-dev:45268]'

thread.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,6 +2213,8 @@ rb_notify_fd_close(int fd)
22132213
if (wfd->fd == fd) {
22142214
rb_thread_t *th = wfd->th;
22152215
VALUE err = th->vm->special_exceptions[ruby_error_stream_closed];
2216+
2217+
wfd->fd = -1; /* ensure we only enqueue once */
22162218
rb_threadptr_pending_interrupt_enque(th, err);
22172219
rb_threadptr_interrupt(th);
22182220
busy = 1;

0 commit comments

Comments
 (0)