Bug #14681
open`syswrite': stream closed in another thread (IOError)
Description
Perhaps related to https://bugs.ruby-lang.org/issues/13632
Here is a sample to reproduce the issue.
#!/usr/bin/env ruby
require 'thread'
puts RUBY_VERSION
100.times.collect do
Thread.new do
input, output = IO.pipe
worker = Thread.new do
sleep(0.1)
output.syswrite('.')
end
input.read(1)
input.close
output.close
worker.join
end
end.each(&:join)
If you run this, you will get output like so:
2.5.0
#<Thread:0x00007fb7a4956ee8@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a50bb468@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4964250@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a49386f0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a493ab08@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495fb88@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a50bbb98@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4948820@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4939820@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a486a458@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4860020@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4970258@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4973f48@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4948618@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495f728@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495f868@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4848628@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4843858@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4809400@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a5085278@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495e0f8@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a48417d8@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a5037c80@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4948398@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4948c30@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4939b18@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4957500@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a480a9b8@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a5036d30@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a5085c50@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495e2b0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495f070@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495e6e8@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a49572d0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495e580@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a494a350@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4811060@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a50842b0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a494bb10@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a493ae00@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a495e878@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a494be30@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4809c70@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a480a4e0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a50b90f0@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:11 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
#<Thread:0x00007fb7a4965600@/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:8 run> terminated with exception (report_on_exception is true):
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
Traceback (most recent call last):
1: from /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `block (3 levels) in <main>'
/private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError)
Exited with status 1 after 0.291 seconds
However, you can clearly see from the order of the sample code it's not possible for such an error to occur. #close
is only invoked after a successful #read
which is only possible after a successful #write
. Yet, the error implies that the write failed because it was already closed.
Updated by ioquatix (Samuel Williams) over 6 years ago
I confirmed the issue also applies to 2.5.1
I add a mutex to the write and close operations (which should not be necessary) and it "fixes" the issue.
100.times.collect do
Thread.new do
mutex = Mutex.new
input, output = IO.pipe
worker = Thread.new do
sleep(0.1)
mutex.synchronize do
output.syswrite('.')
end
end
input.read(1)
mutex.synchronize do
input.close
output.close
end
worker.join
end
end.each(&:join)
Updated by normalperson (Eric Wong) over 6 years ago
Thanks, fixing now.
Updated by normalperson (Eric Wong) over 6 years ago
samuel@oriontransfer.org wrote:
Bug #14681: `syswrite': stream closed in another thread (IOError)
https://bugs.ruby-lang.org/issues/14681
There's two bugs, here, I think. I made r63216 because it
became obvious to me with the timeline shown in the commit message:
https://80x24.org/spew/20180421024614.7362-1-e@80x24.org/raw
However, I have a work-in-progress fix which probably requires
API rework for rb_thread_io_blocking_region:
https://80x24.org/spew/20180421021502.31552-1-e@80x24.org/
Note: the /* TODO: check func() */ in rb_thread_io_blocking_region
But that WIP patch is broken...
I think we need to replace rb_thread_io_blocking_region to
permanently fix your problem. My change to check "val != Qundef"
is insufficient and wrong. But I don't know how reasonable close
notifications can be with APIs like IO.copy_stream and
IO.select which work on multiple IOs, even...
However, you can work around the problem simply:
100.times.collect do
Thread.new do
input, output = IO.pipeworker = Thread.new do sleep(0.1) output.syswrite('.') end input.read(1) input.close output.close worker.join
You should be able to rearrange the order of the last two calls
so worker.join happens before output.close:
worker.join
output.close
Thats should avoid the problem described in
https://80x24.org/spew/20180421021502.31552-1-e@80x24.org/
end
end.each(&:join)
Updated by normalperson (Eric Wong) over 6 years ago
Eric Wong normalperson@yhbt.net wrote:
https://80x24.org/spew/20180421021502.31552-1-e@80x24.org/
Note: the /* TODO: check func() */ in rb_thread_io_blocking_region
But that WIP patch is broken...I think we need to replace rb_thread_io_blocking_region to
permanently fix your problem. My change to check "val != Qundef"
is insufficient and wrong. But I don't know how reasonable close
notifications can be with APIs like IO.copy_stream and
IO.select which work on multiple IOs, even...
Btw, this problem is present since 1.9.3 at least, probably
earlier; and your original script fails on older versions as
well. (but they seem OK with my proposed reordering to
worker.join before output.close)
So maybe it's not so urgent and we can take our time with API
design.
I am thinking of replacing all GVL release functions with
something which takes an opaque attr like pthread_create uses.
It's a bit verbose, but should be extensible:
--- a/io.c
+++ b/io.c
@@ -983,11 +983,19 @@ static ssize_t
rb_write_internal(int fd, const void *buf, size_t count)
{
struct io_internal_write_struct iis;
+ ssize_t w;
+ rb_thread_run_t tr;
+ rb_thread_attr_t attr;
iis.fd = fd;
iis.buf = buf;
iis.capa = count;
- return (ssize_t)rb_thread_io_blocking_region(internal_write_func, &iis, fd);
+ rb_thread_attr_init(&attr, 1);
+ rb_thread_attr_set_fds(&attr, 1, &fd);
+ rb_thread_attr_set_ubf(&attr, RUBY_UBF_IO, NULL);
+ rb_thread_run_do(&tr, &attr, internal_write_func, &iis);
+ rb_thread_run_join(tr, &w);
+ return w;
}
static ssize_t
rb_thread_attr_set_fds would allow setting multiple FDs
for functions like sendfile/splice/copy_file_range/tee,
something rb_thread_io_blocking_region can't do.
(but probably not used for poll/select/ppoll)
rb_thread_attr_set_ubf - to set unblocking function + arg
as with current rb_thread_call_without_gvl2
rb_thread_attr_set_intrfail - set fail-if-interrupted flag
This will allow removing confusing difference between
rb_thread_call_without_gvl and rb_thread_call_without_gvl2
calls (which does which again?)
Future expansion:
rb_thread_attr_set_bind - allow migrating to different native thread
Updated by ioquatix (Samuel Williams) over 6 years ago
Eric, thanks so much for your commitment to fixing this issue and for taking a look at my specific use case.
I will try out your suggestions. If it works, it's good enough.
I look forward to your future bug fix.
Updated by ioquatix (Samuel Williams) over 6 years ago
I reviewed your suggestion, and while it (in theory) works with the original example, it won't work with my actual use case. I have a fixed number of worker threads reading from a shared job queue and executing jobs - when the job is completed, the IO is triggered and on the waiting end the IO is closed once the input is read - there is no join except when the thread pool is stopped.
Updated by ioquatix (Samuel Williams) over 6 years ago
Excuse my ignorance, but if you call write, why can't you just directly invoke ::write
? Why do you need to do rb_thread_io_blocking_region
?
Updated by normalperson (Eric Wong) over 6 years ago
samuel@oriontransfer.org wrote:
Excuse my ignorance, but if you call write, why can't you just
directly invoke::write
? Why do you need to do
rb_thread_io_blocking_region
?
rb_thread_io_blocking_region releases the GVL because write(2) may
block on slow filesystem, full pipe/sockets, etc.
We no longer set O_NONBLOCK on sockets/pipes by default since
1.9+; and but that didn't help with slow filesystems whose
buffers are full (or using weird stuff like O_SYNC/O_DIRECT).
rb_thread_io_blocking_region is slightly different than
rb_thread_call_without_gvl because Ruby has traditionally
signaled cross-thread IO#close with IOError instead of undefined
platform-specific behavior (sometimes EBADF, sometimes blocks
for a long time and succeeds, ...). I'm not sure I actually
agree with this behavior, just stating what things are.
Updated by normalperson (Eric Wong) over 6 years ago
samuel@oriontransfer.org wrote:
I reviewed your suggestion, and while it (in theory) works
with the original example, it won't work with my actual use
case which uses are set of shared threads to implement
background workers - there is no join except when the thread
pool is stopped.
If its threads background workers, perhaps SizedQueue is
better (and probably faster since 2.5).
Or, why bother closing the output early?
Updated by ioquatix (Samuel Williams) over 6 years ago
We no longer set O_NONBLOCK on sockets/pipes by default since
1.9+; and but that didn't help with slow filesystems whose
buffers are full (or using weird stuff like O_SYNC/O_DIRECT).
Can I set this to avoid the breaking code path? I know the write would succeed every time in this case.
signaled cross-thread IO#close
Do you mind explaining what this is? Do you mean if one thread is calling read
and then another thread calls close
while read
is still in progress?
If its threads background workers, perhaps SizedQueue is
better (and probably faster since 2.5).
I did't know about this. Thanks for your suggestion, I will review it.
Updated by normalperson (Eric Wong) over 6 years ago
samuel@oriontransfer.org wrote:
We no longer set O_NONBLOCK on sockets/pipes by default since
1.9+; and but that didn't help with slow filesystems whose
buffers are full (or using weird stuff like O_SYNC/O_DIRECT).
Can I set this to avoid the breaking code path? I know the
write would succeed every time in this case.
In that case, it sounds like you can use write_nonblock instead
of syswrite. *_nonblock functions do not release GVL.
signaled cross-thread IO#close
Do you mind explaining what this is? Do you mean if one thread
is callingread
and then another thread callsclose
while
read
is still in progress?
Exactly
Updated by Eregon (Benoit Daloze) about 2 years ago
- Related to Bug #18455: `IO#close` has poor performance and difficult to understand semantics. added
Updated by ioquatix (Samuel Williams) 7 months ago
- Assignee set to ioquatix (Samuel Williams)
Updated by hsbt (Hiroshi SHIBATA) 2 months ago
- Status changed from Open to Assigned