socketry / async

An awesome asynchronous event-driven reactor for Ruby.
MIT License
2.12k stars 86 forks source link

Task may have ended with unhandled exception when using Async combined with Sequel Fiber concurrency #259

Closed mscrivo closed 1 year ago

mscrivo commented 1 year ago

This is a strange one, to me at least, and may not be an issue, so feel free to close and direct me to starting a discussion instead, but I thought I'd start here first.

Some context: We use Ruby 3.2.2, with the latest version of Async quite successfully for some time in a handful of places that are I/O heavy in our codebase, without issue. We also use Sequel (latest version) as our ORM, with it's default Thread based concurrency primitive.

Issue: I wanted to see if the Sequel Fiber concurrency extension would work for us and help with performance, so I tried it and started seeing some weird behaviour in our test runs. It seems that after enabling that extension, any test that calls code that uses as Async block directly is now failing with NoMethodError errors. Here's an example test output:

  0.0s     warn: Async::Task [oid=0x30d68] [ec=0x30d7c] [pid=85330] [2023-07-19 13:51:16 -0700]
               | Task may have ended with unhandled exception.
               |   NoMethodError: undefined method `foo' for nil:NilClass

foo in this case is a method on a Sequel model class, called within an Async do block. I'm unsure how or why Sequel's fiber extension is causing this breakage.

ioquatix commented 1 year ago

Are you able to give me a simple reproduction/code example that fails?

mscrivo commented 1 year ago

Are you able to give me a simple reproduction/code example that fails?

Will try, I believe it depends on having a DB setup with sequel models, so not super simple, but let me see what I can do.

mscrivo commented 1 year ago

Still no repro unfortunately, been working on setting up something with sqlite that mimics the behaviour of our real code here: https://github.com/mscrivo/sequel-async-bug .. but alas, it's all working great so far. I think the main difference is that in our real app we have a lot more DB associations, so a lot more stuff is getting loaded that I can't easily reproduce. Anyhow, still on it, hoping I can crack the nut 🤞🏼

mscrivo commented 1 year ago

I've been unable to reproduce this outside of our codebase; I can't quite reproduce the same conditions. The more I work with it, the more I think it may be an issue with Sequel rather than Async, so I'll close this out for now.