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

Detect blocking calls in coroutines during tests using BlockBuster #3486

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

cbornet
Copy link

@cbornet cbornet commented Jan 30, 2025

Summary

BlockBuster is a library to detect harmful blocking calls done in the async event loop (when activated, it raises an error if a blocking call is done).
It is just a few lines to integrate with pytest.
Globally, httpx is a good citizen and the only blocking call it detected is mimetypes.guess_type in Request constructor. mimetypes has a global cache so this blocking call is only done once.
Solutions for this would be:

  • defer the mimetype resolution to when the request is actually called and call mimetypes.guess_type in a thread
  • or just accept that it blocks for a short time only once and add an exemption in blockbuster setup.
    I've also seen blocking calls made when using HTTPS but there seems to be no unit tests for async+TLS.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion. (This doesn't apply to typos!)
  • I've added a test for each change that was introduced, and I tried as much as possible to make a single atomic change.
  • I've updated the documentation accordingly.

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.

1 participant