Fix TCPConnector.close() race condition with in-flight DNS resolution#12532
Fix TCPConnector.close() race condition with in-flight DNS resolution#12532prshant70 wants to merge 1 commit into
Conversation
Fixes aio-libs#12497 The TCPConnector.close() method had a race condition where the resolver was closed before marking the connector as closed. This allowed in-flight DNS resolutions to resume and attempt to use a None resolver, causing AttributeError instead of the expected ClientConnectionError. The fix reorders the operations to ensure _closed is set to True (via super().close()) before closing the resolver. This way, any resumed DNS resolutions can properly detect the closed state and bail out. - Reorder close sequence: mark connector closed before closing resolver - Add regression test for in-flight DNS resolution during close
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Merging this PR will improve performance by 8.56%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_read_large_binary_websocket_messages |
48.9 µs | 45 µs | +8.56% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing prshant70:fix/issue-12497-tcpconnector-race-condition (dd7ab1f) with master (65b42bb)2
Footnotes
-
69 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
-
No successful run was found on
master(2e03c13) during the generation of this report, so 65b42bb was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩
|
The test fails and there's already a fix in #12498. |
Fixes #12497
Problem
TCPConnector.close() had a race condition where the resolver was closed before marking the connector as closed. This allowed in-flight DNS resolutions to resume and attempt to use a None resolver, causing AttributeError instead of the expected ClientConnectionError.
Solution
Reordered the operations to ensure _closed is set to True (via super().close()) before closing the resolver. This way, any resumed DNS resolutions can properly detect the closed state and bail out.
Changes
TCPConnector.close()race:AttributeErroron in-flight resolve withaiodns#12497Testing
The new test verifies that in-flight DNS resolutions during close result in proper ClientConnectionError instead of AttributeError.