Skip to content

Can I safely use tokio's task_local on a per-request basis? #2631

Answered by jplatte
edgarogh asked this question in Q&A
Discussion options

You must be logged in to vote

Yes, you can use a task local to pass information about the request to inner middlewares, handlers and IntoResponse impls. Though for all but the last one, you can also use request extensions.

If is however also possible for inner middleware to do parts of its work (including calling the inner service) on different tasks though, making task locals unavailable. This is rare and something I would expect the middleware's docs to point out, though.

Replies: 1 comment 2 replies

Comment options

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

@jplatte
Comment options

Answer selected by edgarogh
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