Replies: 1 comment 9 replies
-
In tokio, the main thread is not actually one of the tokio worker threads. Your infinite handler ties up a tokio worker thread regardless of how Axum is running, but in the case that you spawn the server, it has the chance of running on the same thread as Axum and preventing progress. |
Beta Was this translation helpful? Give feedback.
9 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
why having a blocking handler (or long running) prevents axum from serving new clients -> when we using it with tokio::spawn()
but it works when we just await in main()
working example:
curl 127.0.0.1:3000/1 -> stuck
curl 127.0.0.1:3000/2 -> keeps working
broken example:
curl 127.0.0.1:3000/1 -> stuck
curl 127.0.0.1:3000/2 -> not connected
I know that I should use tokio::task::spawn_blocking and do not call long computation in handlers
but anyways -> blocking 1 handler should not block whole server from serving new clients
Beta Was this translation helpful? Give feedback.
All reactions