Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions lib/process_executer/monitored_pipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ def close
return unless state == :open

@state = :closing
sleep 0.01 until state == :closed
sleep 0.001 until state == :closed
end

# Return the write end of the pipe so that data can be written to it
Expand Down Expand Up @@ -149,6 +149,8 @@ def fileno
# @api private
#
def write(data)
raise IOError, 'closed stream' unless state == :open

pipe_writer.write(data)
end

Expand Down Expand Up @@ -289,7 +291,7 @@ def monitor_pipe
@state = :closing
end
rescue IO::WaitReadable
pipe_reader.wait_readable(0.01)
pipe_reader.wait_readable(0.001)
end

# Read any remaining data from the pipe and close it
Expand Down
7 changes: 7 additions & 0 deletions spec/process_executer/monitored_pipe_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -166,5 +166,12 @@
expect { monitored_pipe.write('world') }.to raise_error(IOError, 'closed stream')
end
end

context 'after the pipe is closed' do
it 'should raise an exception' do
monitored_pipe.close
expect { monitored_pipe.write('hello') }.to raise_error(IOError, 'closed stream')
end
end
end
end