Skip to content

Is it safe to use block_on at the top level of a spawn_blocking call? #3717

Answered by Darksonn
stuhood asked this question in Q&A
Discussion options

You must be logged in to vote

In general, yes, using block_on at the top level of a spawn_blocking is supported, but if you make use of this feature, there are certain types of behavior that can deadlock (this applies to spawn_blocking in general, whether or not you use block_on inside it). One rule you can follow which guarantees that you have no deadlocks due to the spawn_blocking pool capacity is that any task running on it (using block_on or not) should eventually exit on its own even if all other threads were paused for the full duration of the spawn_blocking call.

So for example, if your spawn_blocking task cannot complete until some other spawn_blocking task completes, then this can cause a deadlock given enoug…

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@stuhood
Comment options

@Darksonn
Comment options

Answer selected by stuhood
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants