pulsar-client-go icon indicating copy to clipboard operation
pulsar-client-go copied to clipboard

Fix: SendAsync callback was not invoked when producer is in reconnecting

Open nodece opened this issue 9 months ago • 2 comments

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 TestProducerSendWithContext test:
    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 TestProducerKeepReconnectingAndThenCallSendAsync that verifies:
    • SendAsync callbacks are properly invoked with appropriate errors during reconnection.
    • The fix works correctly with both batching enabled and disabled configurations.

nodece avatar Mar 12 '25 17:03 nodece

@gunli Could you have a chance to review?

nodece avatar Mar 16 '25 15:03 nodece

ping @RobertIndie

nodece avatar Apr 07 '25 04:04 nodece

Closed by https://github.com/apache/pulsar-client-go/pull/1422

nodece avatar Sep 16 '25 04:09 nodece