gh-155027: Make test_asyncio's socket harness able to fail a test - #155028
Open
matthiasgoergens wants to merge 1 commit into
Open
gh-155027: Make test_asyncio's socket harness able to fail a test#155028matthiasgoergens wants to merge 1 commit into
matthiasgoergens wants to merge 1 commit into
Conversation
_abort_socket_test() called self.fail() from the client/server thread. The resulting AssertionError escapes Thread.run() without ever reaching TestCase.run(), so an error in the server half of a socket test did not fail it. Record the exception instead and re-raise it from tearDown(). Also stop the event loop with call_soon_threadsafe() rather than calling loop.stop() directly from a non-main thread.
matthiasgoergens
requested review from
1st1,
asvetlov,
kumaraditya303 and
willingc
as code owners
August 1, 2026 13:19
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.
_abort_socket_test()calledself.fail()from the client or server thread.self.fail()raisesAssertionErrorin the calling thread, and both call sites are inside aThread.run(), so the exception escapes the thread without ever reachingTestCase.run()— the test still reportsok. This patch records the exception instead and re-raises it fromtearDown(), on the main thread, where unittest can see it.It also replaces
self.loop.stop()withself.loop.call_soon_threadsafe(self.loop.stop). Event loops are not thread-safe and this call was being made from a non-main thread.Background, measurements and the history are in #155027. In short: this has never worked in any release since 3.7, and since 3.10 the only thing that notices is regrtest's threading excepthook, which wins the race roughly half the time.
Verification
Same binary, the patch toggled on and off, running a test whose server prog raises
ConnectionResetError— the shape of the Windows CI failure that prompted this:mainSUCCESS(recorded only as "env changed")FAILURE— 1 test failedThe test module used is not included here; see "open question" below.
Please treat this as potentially disruptive
I would rather flag this clearly than have it discovered on the buildbots.
The diff is small but its effect is not local. These failures currently do not fail tests, so making the abort work means any latent failure in the client or server half of a socket test will start failing. The mixin is used by
test_sslproto,test_ssl,test_events,test_server,test_streams,test_buffered_proto,test_sock_lowlevelandtest_unix_events.What I can say from here:
test_asynciois green on Linux with the patch, 2,819 tests, five consecutive runs, no flakes.What I cannot say: anything about the other platforms, and that is where the risk actually is. The failure that prompted this was Windows-only, and I expect it to go red. Platform-specific socket behaviour is precisely what a Linux dev box cannot tell you about, and eight years of accumulated silence is a lot of surface to uncover at once.
So I am not assuming this should merge as-is. Reasonable alternatives, if maintainers prefer: land it early in a release cycle rather than near a beta; or land the diagnosis first, see what turns red across the buildbot fleet, fix those, and enable the abort afterwards. I am happy to split it that way, or to drop it if the churn is not judged worth the benefit.
Open question for reviewers
I have not added a regression test. A natural one would assert that a failing server prog fails the test, but it would have to do so by asserting that a test fails, which needs care to write well in this suite. Happy to add one in whatever form is preferred — or to leave it, given that the change is itself test-infrastructure.