Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash blocking inside tokio. Fixes #1017 #2239

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

ramon-garcia
Copy link

@ramon-garcia ramon-garcia commented Apr 6, 2024

This pull request makes it possible to run blocking requests inside Tokio runtime without crashing.

This should fix issue #1017

@ramon-garcia ramon-garcia force-pushed the fix-crash-blocking-inside-tokio branch from c80e77a to 92f99ed Compare April 6, 2024 20:25
@ramon-garcia
Copy link
Author

Hello, please, could you allow the CI to run?

@ramon-garcia
Copy link
Author

Hello. Any comments?

@ramon-garcia
Copy link
Author

Ping

@seanmonstar
Copy link
Owner

Thanks for the PR!

However, this is currently by design. Blocking inside a task, even with block_in_place, can have unexpected consequences. This currently tries to warn you in development that this is a problem.

@ramon-garcia
Copy link
Author

I followed the advice from tokio-rs/tokio#5843 . It looks like it works correctly provided that one is using the multithreaded runtime.

There are a number of cases where this is useful. For instance, one has a codebase of synchronous code, and wants to call it from an synchronous context, and converting the code does not pay off (because the web requests are really the only activity at this time).

Notice the confusing behavior, when one calls a library function from an asynchronous context, and gets a crash because some part of that library makes a web request.

What unexpected consequences could have blocking code inside block_in_place and block_on?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants