Repository navigation
Conversation
_AsyncioTransport.abort(error) dropped the error and asyncio then calls
connection_lost(None), so a request timeout or a broker disconnect failed
in-flight requests with Cancelled and resolved close_future as a clean
close. Keep the abort error for the protocol adapter, report a peer EOF
as KafkaConnectionError('socket disconnected') and wrap socket errors in
KafkaConnectionError, as KafkaTCPTransport does.
On a busy runner the listener could reset the socket before connect() completed, so create_connection itself failed.
Author
|
The four red jobs all failed on my new |
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
With the asyncio backend (
net='asyncio', or the defaultnet=Noneinside a running asyncio loop), a connection closed with an error looks like a clean close: in-flight requests fail withCancelledinstead ofRequestTimedOutErrororKafkaConnectionError, andclose_futuresucceeds.TxnRequestHandler.on_completeretries only those two errors and makes anything else fatal (L859-L873), so on asyncio the retry from #3192 never applies, and a broker disconnect makes the transactional producer fatal.Root Cause
A request timeout calls
close(RequestTimedOutError(...))(connection.py L191), which callstransport.abort(error)(L330-L339).KafkaTCPTransport.aborthands that error toprotocol.connection_lost(transport.py L187-L199), and so doesKafkaSSLTransport._AsyncioTransport.abortdrops it (asyncio_backend.py L428-L429), asyncio then callsconnection_lost(None), andfail_in_flight_requests(None)usesCancelled()(connection.py L248).The selector transport also reports a peer EOF as
KafkaConnectionError('socket disconnected')and wraps socket errors inKafkaConnectionError(transport.py L111-L123). The asyncio adapter passesNoneand rawOSErrors through.Changes
_AsyncioTransport.abortkeeps the error, unless the transport is already closing, and the protocol adapter passes it toconnection_lost. Aclose()followed byabort(error)stays a clean close, as on the selector.KafkaConnectionError('socket disconnected')and wraps a non-Kafka exception inKafkaConnectionError. Kafka errors, such as aKafkaProtocolErrorraised fromdata_received, pass through unchanged.The selector backend is unchanged. On asyncio, an error close now fails
close_future, so it logs "Connection lost" and triggers the manager's metadata refresh as the selector does. An idle connection closed by the broker logs "Connection lost: socket disconnected".A loopback listener that never answers,
request_timeout_ms=300, twoMetadataRequests, at fa42377:Tests
The new tests in
test/net/backend/test_asyncio_backend.pycover:abort(error);close()thenabort(error);KafkaConnectionrequest timeout.The abort, EOF, reset and request-timeout tests fail on master.
pytest test --ignore=test/integration(2765 passed) andmake lintpass on Python 3.12, and the backend tests pass on 3.8, 3.9, 3.10 and 3.14. I did not run the integration tests (no Kafka here) or TLS on asyncio.Written with AI assistance (Claude); I have reviewed the change.