tests: disable gRPC fork handlers to fix flaky fork() abort#1905
Merged
Conversation
The suite intermittently fails in CI due to (pexpect spawned) labgrid-client being killed during teardown by SIGABRT and gRPC C-core aborting after a fork: fork_posix.cc:71] Other threads are currently calling into gRPC, skipping fork() handlers ev_epoll1_linux.cc:1125] Check failed: next_worker->state == KICKED gRPC documents that fork() is only safe if gRPC objects are created in the child after the fork [1]. The tests do the opposite: the pytest process spawns the labgrid-client commands via pexpect (using forkpty) while gRPC is already initialized in it (imported at collection, and used in-process by the coordinator tests). To partially support this, gRPC installs a pthread_atfork handler that tries to quiesce its poller across the fork. When another thread is in the C-core at fork time the handler loses that race, skips the reset, and the forked child aborts on the inconsistent poller before it can exec the client. The problem could never be reproduced locally; it likely occurs more often in CI because scheduling pressure makes the race more likely to trigger. Set GRPC_ENABLE_FORK_SUPPORT=0 to disable the handler. This is the documented remedy for callers that always exec() after fork() and never reuse a channel across fork(), which is what the test suite does. Set it in conftest.py before pytest's collection imports grpc. [1] https://github.com/grpc/grpc/blob/master/doc/fork_support.md Signed-off-by: Bastian Krause <bst@pengutronix.de>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1905 +/- ##
======================================
Coverage 45.9% 45.9%
======================================
Files 180 180
Lines 14500 14500
======================================
Hits 6666 6666
Misses 7834 7834
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Emantor
approved these changes
Jun 29, 2026
Member
|
I looked at this briefly on friday too when wondering about the test failures, thanks for the deep dive and fixing the tests 👍 |
Member
Author
|
Although this is not really material for "stable", having a stable CI (pun intended) would be worth it :) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The test suite intermittently fails in CI due to (pexpect spawned) labgrid-client being killed during teardown by SIGABRT and gRPC C-core aborting after a fork:
gRPC documents that fork() is only safe if gRPC objects are created in the child after the fork [1]. The tests do the opposite: the pytest process spawns the labgrid-client commands via pexpect (using forkpty) while gRPC is already initialized in it (imported at collection, and used in-process by the coordinator tests). To partially support this, gRPC installs a pthread_atfork handler that tries to quiesce its poller across the fork. When another thread is in the C-core at fork time the handler loses that race, skips the reset, and the forked child aborts on the inconsistent poller before it can exec the client.
The problem could never be reproduced locally; it likely occurs more often in CI because scheduling pressure makes the race more likely to trigger.
Set GRPC_ENABLE_FORK_SUPPORT=0 to disable the handler. This is the documented remedy for callers that always exec() after fork() and never reuse a channel across fork(), which is what the test suite does. Set it in conftest.py before pytest's collection imports grpc.
[1] https://github.com/grpc/grpc/blob/master/doc/fork_support.md
Checklist