pulsar-client-go
pulsar-client-go copied to clipboard
Fix: SendAsync callback was not invoked when producer is in reconnecting
Fixes #1332
Motivation
When the producer reconnects, the batching/non-batching messages can not be added to the pending queue, so the timeout error can not be triggered. This leads to situations where SendAsync callbacks are never invoked when the producer is in a reconnecting state, potentially causing resource leaks and unresponsive applications.
Modifications
- Separated internal data writing and network requests from the event loop.
- Data flow: SendAsync -> dataChan -> writeChan -> broker.
- Fixed payload size handling in
TestProducerSendWithContexttest:time="2025-03-16T09:05:13Z" level=error msg="Single message serialize failed %!s(<nil>)" error="encryptedPayload exceeds MaxMessageSize, size: 1048607, MaxMessageSize: 1048576" producerID=1 producer_name=standalone-0- 358 topic="persistent://public/default/my-topic-857833034" - Added a comprehensive test case
TestProducerKeepReconnectingAndThenCallSendAsyncthat verifies:- SendAsync callbacks are properly invoked with appropriate errors during reconnection.
- The fix works correctly with both batching enabled and disabled configurations.
@gunli Could you have a chance to review?
ping @RobertIndie
Closed by https://github.com/apache/pulsar-client-go/pull/1422