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

[Python] Handle BlockingIOError if multiple loops are bound to PollerCompletionQueue #36096

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

Conversation

maffoo
Copy link

@maffoo maffoo commented Mar 12, 2024

Fixes #25364

When using grpc with multiple asyncio event loops in different threads, we may have multiple loops bound to the same PollerCompletionQueue. If the event loops support file descriptor monitoring, each loop will be configured with loop.add_reader to handle read events on the notification socket. This means that when completion events are available, PollerCompletionQueue._handle_events may be called multiple times for the different loops, but only one call will actually receive the byte written to the notification socket. The other calls will raise BlockingIOError, which then bubbles up and gets printed by the event loop's default exception handler, resulting in spurious error messages since things are in fact working fine. This changes _handle_events to catch and supress these BlockingIOErrors.

@gnossen
Copy link
Contributor

gnossen commented Mar 15, 2024

Thanks for the contribution! I don't believe we currently have any tests that cover operating with multiple event loops. Do you think you could help by contribution one that replicates your setup?

@XuanWang-Amos XuanWang-Amos added release notes: no Indicates if PR should not be in release notes kokoro:run labels Mar 15, 2024
@maffoo
Copy link
Author

maffoo commented Mar 18, 2024

@gnossen, I added a basic test of using grpc.aio from multiple threads, please take a look. I haven't been able to run this locally because grpc is failing to build for me. I tried to follow the instructions and ran

python tools/run_tests/run_tests.py -l python --compiler python3.12

in a python 3.12 virtualenv, but that fails with an error while building wheels. Any additional pointers you have about running tests locally would be greatly appreciated.

@XuanWang-Amos
Copy link
Contributor

Hi, thanks for contributing the test! Do you mind share more information about the failures? In the meanwhile, you can also trigger the test using bazel like this:

bazel test "//src/python/grpcio_tests/tests_aio/unit:multithread_test"

@XuanWang-Amos
Copy link
Contributor

Looks like the new test is timing out, do you mind take a look?

@gnossen
Copy link
Contributor

gnossen commented Apr 12, 2024

Looks like the distribtest failure is an unrelated non-hermetic regression on the master branch unrelated to this PR. (cause). We'll take care of that out of band.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kokoro:run lang/Python release notes: no Indicates if PR should not be in release notes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Multi-thread support for python asyncio gRPC clients
5 participants