From: samuel@... Date: 2018-04-21T22:12:56+00:00 Subject: [ruby-core:86647] [Ruby trunk Bug#14681] `syswrite': stream closed in another thread (IOError) Issue #14681 has been updated by ioquatix (Samuel Williams). > 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. ---------------------------------------- Bug #14681: `syswrite': stream closed in another thread (IOError) https://bugs.ruby-lang.org/issues/14681#change-71604 * Author: ioquatix (Samuel Williams) * Status: Open * Priority: Normal * Assignee: * Target version: * ruby -v: 2.5.0 * Backport: 2.3: UNKNOWN, 2.4: UNKNOWN, 2.5: UNKNOWN ---------------------------------------- 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 # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /private/var/folders/3x/tvygzl0s65520b6t4tzqbt980000gn/T/16789369-c982-4cbc-a0b3-c836af60bf03:13:in `syswrite': stream closed in another thread (IOError) # 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
' /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
' /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. -- https://bugs.ruby-lang.org/ Unsubscribe: