Cancelling DataLoader.load
futures doesn't cancel the underlying task
#3606
Labels
bug
Something isn't working
Describe the Bug
I'm working in a codebase where we use DataLoaders quite heavily with an SQLAlchemy-based database client. Often, we'd like to await two or more
load()
futures. We use FastAPI and rely on it's dependency injection to handle SQLAlchemy session, forcibly closing it at the end of a request. Unfortunately, currently we're hitting a problem where usingasyncio.gather()
or evenasyncio.TaskGroup()
results in hard to debug errors, whereby dataloader task continues to run even if theload()
future is cancelled.To summarise, there's no way to cancel or wait for the underlying dataloader task, making it impossible to cleanly close the resources used by the dataloader.
I've got a branch (diff) with a test case that shows this problem.
I've also got a very speculative branch that addresses this issue and improves general handling of task cancellations in the DataLoader. It's not 100% done yet. I'll try to finish it & open a PR in the next few days.
System Information
Additional Context
A little bit like #3414, this issue has to do with keeping track of tasks/futures and a proper resource cleanup.
Upvote & Fund
The text was updated successfully, but these errors were encountered: