Skip to content

Commit

Permalink
It's possible that the monitor was closed before calling resume. This…
Browse files Browse the repository at this point in the history
… happens if `select` returns several tasks to resume, and a previous one calls close on this wrapper.
  • Loading branch information
ioquatix committed Aug 6, 2018
1 parent 110cec8 commit 5cbec1d
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/async/version.rb
Expand Up @@ -19,5 +19,5 @@
# THE SOFTWARE.

module Async
VERSION = "1.10.0"
VERSION = "1.10.1"
end
3 changes: 3 additions & 0 deletions lib/async/wrapper.rb
Expand Up @@ -50,6 +50,9 @@ def initialize(io, reactor = nil)
end

def resume(*args)
# It's possible that the monitor was closed before calling resume.
return unless @monitor

readiness = @monitor.readiness

if @readable and (readiness == :r or readiness == :rw)
Expand Down
14 changes: 10 additions & 4 deletions spec/async/wrapper_spec.rb
Expand Up @@ -81,13 +81,19 @@
it "can be cancelled while waiting to be readable" do
reactor.async do
expect do
output.wait_readable
input.wait_readable
end.to raise_error(Async::Wrapper::Cancelled)
end

reactor.async do
input.close
end
# This reproduces the race condition that can occur if two tasks are resumed in sequence.

# Resume task 1 which closes IO:
output.close

# Resume task 2:
expect do
output.resume
end.to_not raise_error
end

it "can be cancelled" do
Expand Down

0 comments on commit 5cbec1d

Please sign in to comment.