Skip to content

Commit 0ad0a88

Browse files
authored
Fix handling of TimeoutError in io_wait. (#274)
1 parent 7830d3e commit 0ad0a88

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

lib/async/scheduler.rb

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -171,17 +171,11 @@ def io_wait(io, events, timeout = nil)
171171

172172
if timeout
173173
timer = @timers.after(timeout) do
174-
fiber.raise(TimeoutError)
174+
fiber.transfer
175175
end
176176
end
177177

178-
# Console.logger.info(self, "-> io_wait", fiber, io, events)
179-
events = @selector.io_wait(fiber, io, events)
180-
# Console.logger.info(self, "<- io_wait", fiber, io, events)
181-
182-
return events
183-
rescue TimeoutError
184-
return false
178+
return @selector.io_wait(fiber, io, events)
185179
ensure
186180
timer&.cancel
187181
end

test/async/task.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,14 @@ def after
596596
expect(state).to be == :timeout
597597
end
598598

599-
it "will timeout while getting from stdin" do
599+
it "will timeout while getting from input" do
600+
input, output = IO.pipe
600601
error = nil
601602

602603
reactor.async do |task|
603604
begin
604-
task.with_timeout(0.1) {STDIN.gets}
605+
# This can invoke `io_wait`, which previously had `rescue TimeoutError`, causing the timeout to be ignored.
606+
task.with_timeout(0.1) {input.gets}
605607
rescue Async::TimeoutError => error
606608
# Ignore.
607609
end
@@ -610,6 +612,9 @@ def after
610612
reactor.run
611613

612614
expect(error).to be_a(Async::TimeoutError)
615+
ensure
616+
input.close
617+
output.close
613618
end
614619

615620
it "won't timeout if execution completes in time" do

0 commit comments

Comments
 (0)