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 using BlockBuster #10433

Merged
merged 9 commits into from
Feb 20, 2025

Conversation

cbornet
Copy link
Contributor

@cbornet cbornet commented Feb 6, 2025

What do these changes do?

This PR uses the blockbuster library to detect blocking calls made in the asyncio event loop during unit tests.
Avoiding blocking calls is hard as these can be deeply buried in the code or made in 3rd party libraries.
Blockbuster makes it easier to detect them by raising an exception when a call is made to a known blocking function (eg: time.sleep).

Are there changes in behavior for the user?

No

Is it a substantial burden for the maintainers to support this?

I think no. In 5 years, it's just a few lines to remove if you don't want to use it anymore.

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
    • The format is <Name> <Surname>.
    • Please keep alphabetical order, the file is sorted by names.
  • Add a new news fragment into the CHANGES/ folder

@cbornet cbornet force-pushed the blockbuster branch 2 times, most recently from 1556000 to d0c591f Compare February 6, 2025 16:32
@bdraco
Copy link
Member

bdraco commented Feb 6, 2025

I think this is a very nice change. I'm going to run out of time to review it today.

I'd add excludes for the known issues and add inline comments that they blocking I/O so they can be fixed when someone h as time to work out each one.

Copy link

codspeed-hq bot commented Feb 8, 2025

CodSpeed Performance Report

Merging #10433 will improve performances by 11.57%

Comparing cbornet:blockbuster (70880b2) with master (ed84464)

Summary

⚡ 1 improvements
✅ 47 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
test_one_hundred_get_requests_iter_chunks_on_512kib_chunked_payload[pyloop] 108.1 ms 96.9 ms +11.57%

@cbornet cbornet force-pushed the blockbuster branch 4 times, most recently from 0e67b36 to 08e02f5 Compare February 8, 2025 15:06
@cbornet
Copy link
Contributor Author

cbornet commented Feb 8, 2025

I'd add excludes for the known issues and add inline comments that they blocking I/O so they can be fixed when someone h as time to work out each one.

done in 08e02f5

@cbornet cbornet force-pushed the blockbuster branch 5 times, most recently from 32a6018 to 79b1401 Compare February 8, 2025 16:33
Copy link

codecov bot commented Feb 8, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 98.70%. Comparing base (ed84464) to head (70880b2).
Report is 3 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #10433   +/-   ##
=======================================
  Coverage   98.70%   98.70%           
=======================================
  Files         122      122           
  Lines       37191    37198    +7     
  Branches     2056     2060    +4     
=======================================
+ Hits        36709    36716    +7     
  Misses        335      335           
  Partials      147      147           
Flag Coverage Δ
CI-GHA 98.59% <100.00%> (+<0.01%) ⬆️
OS-Linux 98.25% <100.00%> (+<0.01%) ⬆️
OS-Windows 96.18% <100.00%> (+<0.01%) ⬆️
OS-macOS 97.37% <100.00%> (+<0.01%) ⬆️
Py-3.10.11 97.28% <100.00%> (-0.01%) ⬇️
Py-3.10.16 97.82% <100.00%> (+<0.01%) ⬆️
Py-3.11.11 97.86% <100.00%> (-0.05%) ⬇️
Py-3.11.9 97.36% <100.00%> (+<0.01%) ⬆️
Py-3.12.8 97.15% <100.00%> (-0.01%) ⬇️
Py-3.12.9 98.34% <100.00%> (+<0.01%) ⬆️
Py-3.13.1 97.15% <100.00%> (-0.01%) ⬇️
Py-3.13.2 98.33% <100.00%> (+<0.01%) ⬆️
Py-3.9.13 97.15% <100.00%> (-0.02%) ⬇️
Py-3.9.21 97.69% <100.00%> (-0.01%) ⬇️
Py-pypy7.3.16 83.51% <83.87%> (-13.79%) ⬇️
VM-macos 97.37% <100.00%> (+<0.01%) ⬆️
VM-ubuntu 98.25% <100.00%> (+<0.01%) ⬆️
VM-windows 96.18% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cbornet cbornet force-pushed the blockbuster branch 2 times, most recently from ab7b7fb to 2328c42 Compare February 10, 2025 22:10
@psf-chronographer psf-chronographer bot added the bot:chronographer:provided There is a change note present in this PR label Feb 10, 2025
@cbornet cbornet force-pushed the blockbuster branch 2 times, most recently from ecb84cd to b7cec65 Compare February 11, 2025 01:11
@bdraco
Copy link
Member

bdraco commented Feb 11, 2025

It looks like the checks are running in the benchmarks which is benchmarking the time for the checks. They should be excluded from the benchmark runs

@Dreamsorcerer
Copy link
Member

Tests were working a few days ago, right? Maybe the version of blockbuster needs to be downgraded again?

@cbornet cbornet force-pushed the blockbuster branch 4 times, most recently from cc0bd42 to 845d2f1 Compare February 20, 2025 17:13
@cbornet cbornet force-pushed the blockbuster branch 2 times, most recently from c0f19dc to 60f0a64 Compare February 20, 2025 17:40
@bdraco
Copy link
Member

bdraco commented Feb 20, 2025

Thanks @cbornet

@bdraco bdraco merged commit 0c4b1c7 into aio-libs:master Feb 20, 2025
40 checks passed
Copy link
Contributor

patchback bot commented Feb 20, 2025

Backport to 3.12: 💔 cherry-picking failed — conflicts found

❌ Failed to cleanly apply 0c4b1c7 on top of patchback/backports/3.12/0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32/pr-10433

Backporting merged PR #10433 into master

  1. Ensure you have a local repo clone of your fork. Unless you cloned it
    from the upstream, this would be your origin remote.
  2. Make sure you have an upstream repo added as a remote too. In these
    instructions you'll refer to it by the name upstream. If you don't
    have it, here's how you can add it:
    $ git remote add upstream https://github.com/aio-libs/aiohttp.git
  3. Ensure you have the latest copy of upstream and prepare a branch
    that will hold the backported code:
    $ git fetch upstream
    $ git checkout -b patchback/backports/3.12/0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32/pr-10433 upstream/3.12
  4. Now, cherry-pick PR Detect blocking calls in coroutines using BlockBuster #10433 contents into that branch:
    $ git cherry-pick -x 0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32
    If it'll yell at you with something like fatal: Commit 0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32 is a merge but no -m option was given., add -m 1 as follows instead:
    $ git cherry-pick -m1 -x 0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32
  5. At this point, you'll probably encounter some merge conflicts. You must
    resolve them in to preserve the patch from PR Detect blocking calls in coroutines using BlockBuster #10433 as close to the
    original as possible.
  6. Push this branch to your fork on GitHub:
    $ git push origin patchback/backports/3.12/0c4b1c74cd7bffb544dacb4a4d8793f80fd4ad32/pr-10433
  7. Create a PR, ensure that the CI is green. If it's not — update it so that
    the tests and any other checks pass. This is it!
    Now relax and wait for the maintainers to process your pull request
    when they have some cycles to do reviews. Don't worry — they'll tell you if
    any improvements are necessary when the time comes!

🤖 @patchback
I'm built with octomachinery and
my source is open — https://github.com/sanitizers/patchback-github-app.

@bdraco
Copy link
Member

bdraco commented Feb 20, 2025

@cbornet Looks like this couldn't be backported automatically, can you take a look?

@cbornet cbornet deleted the blockbuster branch February 20, 2025 22:52
cbornet added a commit to cbornet/aiohttp that referenced this pull request Feb 20, 2025
Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
(cherry picked from commit 0c4b1c7)
cbornet added a commit to cbornet/aiohttp that referenced this pull request Feb 20, 2025
cbornet added a commit to cbornet/aiohttp that referenced this pull request Feb 21, 2025
cbornet added a commit to cbornet/aiohttp that referenced this pull request Feb 21, 2025
bdraco pushed a commit that referenced this pull request Feb 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport-3.12 Trigger automatic backporting to the 3.12 release branch by Patchback robot bot:chronographer:provided There is a change note present in this PR
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants