asgiref icon indicating copy to clipboard operation
asgiref copied to clipboard

sync_to_async detects deadlock in case of issue in loop.run_in_executor

Open namezys opened this issue 10 months ago • 2 comments

Long story:

  • We randomly get a run time error: "Single thread executor already being used, would deadlock"`.
  • However, there was another error: RuntimeError: cannot schedule new futures after shutdown. I started to investigate, but it was unclear what error caused this issue.

Even if it does not solve my bugs, I found that exception from loop.run_in_executor in "SyncToAsync.call" results in marking deadlock_context of SyncToAsync set true forever. Of course, this code can not work anymore, but this error is hiding real issues.

Looks like this bug can not affect the correct execution, but I spent too much time to realise that there is no problem related to deadlocks in sync_to_async.

Probably, I will be able to submit fix of it. It's pretty easy.

namezys avatar Feb 27 '25 19:02 namezys

@namezys Please do. A test case showing the issue would be super to see. Thanks.

carltongibson avatar Feb 27 '25 19:02 carltongibson

@carltongibson oops, did it long time ago but haven't mentioned it here #497

namezys avatar Jun 16 '25 12:06 namezys