nodece commented on issue #1481:
URL: 
https://github.com/apache/pulsar-client-go/issues/1481#issuecomment-4412138012

   ## Suggested Fix (Aligned with Java Client Behavior)
   
   After analyzing the Java client's reconnection design, I'd suggest the 
following approach:
   
   ### 1. During consumer creation — respect `maxReconnectToBroker`
   
   When the consumer is in the `Connecting`/initializing phase and fails to 
connect to the broker, the max retry limit should be honored. Once exhausted:
   
   - Complete the `subscribe` future with an exception so the caller gets 
notified
   - Close/cleanup the consumer and transition to `Failed` state
   - This is consistent with Java client's `ConsumerImpl.connectionFailed()`:
   
   ```java
   // Java: ConsumerImpl.java
   if (nonRetriableError || timeout) {
       subscribeFuture.completeExceptionally(exception);
       fail(exception);
       closeConsumerTasks();
       deregisterFromClientCnx();
       client.cleanupConsumer(this);
       return false; // stop retrying
   }
   ```
   
   ### 2. After consumer is already connected — remove the max retry limit
   
   For an already-connected consumer that loses its connection, the 
`maxReconnectToBroker` limit should **not** apply. Instead, the consumer should 
retry indefinitely with exponential backoff (capped at `maxBackoff`).
   
   The key insight from Java client is that `maxBackoff` is a **delay 
ceiling**, not a retry termination signal. Once the backoff reaches 
`maxBackoff`, the consumer continues retrying at that interval forever. The 
broker recovers → consumer reconnects automatically → no silent failure.
   
   ```java
   // Java: ConnectionHandler.java — reconnectLater has no stop condition
   void reconnectLater(Throwable exception) {
       long delayMs = backoff.next().toMillis(); // always returns a valid 
value, never "give up"
       state.client.timer().newTimeout(timeout -> grabCnx(), delayMs, 
TimeUnit.MILLISECONDS);
   }
   ```
   
   ### Why this matters
   
   The current Go behavior (`IsMaxBackoffReached` → stop retrying → no 
notification) is the worst possible outcome: the consumer enters a permanently 
silent state with no way for the user to detect it or recover. Compared to 
Java's approach (infinite retry at capped interval), the Go consumer is 
strictly worse — it silently stops consuming while the user believes everything 
is fine.
   
   ### Summary of behavior change
   
   | Phase | Current (Go) | Proposed |
   |-------|-------------|----------|
   | Consumer creation | No limit, no notification | Honor max retry, notify on 
failure |
   | Already connected | Stop retrying at max backoff, silent | Retry 
indefinitely with backoff cap |
   
   Ref: Java client source — `ConsumerImpl.connectionFailed()`, 
`ConnectionHandler.reconnectLater()`, `Backoff.next()`.


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to