Closed paddor closed 2 days ago
Hmm, that's weird. I'll take a look.
I'm porting our core library from EventMachine to Async. Maybe Async is not the problem. I only see this error after sending SIGINT.
It should be robust but this is a tricky edge case. Are you able to share more of your code?
I don't think so. For now I've wrapped the load computation in that method in if @selector
. I've just started porting, so there are still other problems. I'll keep porting/investigating, and come back.
Okay great... I'll see if I can figure out what's going on.
The port of the core library is mostly done. Apps using it can start, but the patch I made in async is still necessary.
Are you closing the scheduler from within an async block?
begin
@selector.select(interval)
rescue Errno::EINTR
# Ignore.
end
@timers.fire
# Compute load:
end_time = Async::Clock.now
total_duration = end_time - start_time
idle_duration = @selector.idle_duration
Between @selector.select(interval)
and @selector.idle_duration
you must have some how caused #close
to be invoked... is that possible in your code?
Yeah, an Async
-block was used to Async::Task#stop
the final task.
So in this multi-process, actor model app, I used to do Async { actor.shutdown }
in the SIGTERM
handler of the child processes. This used to be wrapped in EM.add_timer(0)
to avoid mutex interaction in trap context from Ruby's Logger
(used in actor.shutdown
). I've now moved away from the stdlib Logger
, which means it works in trap context. That means there's no more Async { ... }
block in the signal handler. It works fine now.
I'm still getting used to the very different thought model. I'm still too used to EM.
Generally speaking, you should avoid using traps in Async code. The event loop uses Ruby's normal trap mechanisms to convert them into exceptions which are raised at predictable times.