Skip to content

feat: regard ProducerBlockedQuotaExceededException as retryable exception to continue to reconnect - #1457

Merged
RobertIndie merged 1 commit into
apache:masterfrom
geniusjoe:dev/ProducerBlockedQuotaExceededException
Mar 20, 2026
Merged

RobertIndie merged 1 commit into
apache:masterfrom
geniusjoe:dev/ProducerBlockedQuotaExceededException

Conversation

@geniusjoe

@geniusjoe geniusjoe commented Jan 20, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #1134
Master Issue: #1128

Motivation

Currently, the Go client handles connections in two ways:

  1. If the current connection is an initialization connection, meaning when the producer is initialized for the first time, the grabCnx()method will not trigger retry logic. If an error occurs, it will be directly returned to the caller.
  2. If the current connection is an already active connection, the runEventsLoop() method will detect the disconnection and call the reconnectToBroker() method to re-establish the connection. During reconnection, the method identifies whether the current exception is a retryable error. If it is a retryable error, the internal.Retry() inside the reconnectToBroker() method will retry indefinitely based on the backoff strategy. If it is a non-retryable error, such as the current errMsgProducerBlockedQuotaExceededException, the partition producer will be closed, causing any following messages sent to that partition to result in a SendTimeoutError.

Since the backlogQuotaExceedException can be resolved by modifying the TTL or increasing consumption speed, it is likely to recover after some retry attempts. I believe the exception handling for errMsgProducerBlockedQuotaExceededException in the reconnectToBroker() method should align as closely as possible with the Java implementation. Java’s current retry logic for connections is as follows:

  1. If an error is received after sending a message or a heartbeat times out, the callback function handleSendError() is triggered to close the connection.
  2. When the connection is closed, the connectionClosed method is called, which in turn invokes the grabCnx() method, and subsequently grabCnx() calls the connectionOpened() method to reconnect:
// Schedule a reconnection task
state.client.timer().newTimeout(timeout -> {
    log.info("[{}] [{}] Reconnecting after timeout", state.topic, state.getHandlerName());
    grabCnx();  // Re-establish the connection
}, delayMs, TimeUnit.MILLISECONDS);
  1. If the connection still fails in the connectionOpened() method, the client will execute different logic based on the current exception. For the ProducerBlockedQuotaExceededException exception, the Java client does not treat it as an isUnrecoverableError. Instead, it first cleans up the pending messages and then attempts to reconnect.

Modifications

  1. To maintain consistency with the Java client, I suggest that when errMsgProducerBlockedQuotaExceededException is encountered in reconnectToBroker(), only failPendingMessages() should be executed, but the connection should not be closed. Specifically, the code should be modified as follows:
if strings.Contains(errMsg, errMsgProducerBlockedQuotaExceededException) {
    p.log.Warn("Producer was blocked by quota exceed exception, failing pending messages, stop reconnecting")
    p.failPendingMessages(errors.Join(ErrProducerBlockedQuotaExceeded, err))
    // Do not close the connection here
    // return struct{}{}, err
}
  1. Update the golangci-lint version in the Makefile from v1.61.0 to v1.64.2, which already meets the minimum requirement for Golang 1.24.

Verifying this change

  • Make sure that the change passes the CI checks.

This change added tests and can be verified as follows:
TestProducerReconnectWhenBacklogQuotaExceed

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (no)
  • The public API: (no)
  • The schema: (no)
  • The default values of configurations: (no)
  • The wire protocol: (no)

Documentation

  • Does this pull request introduce a new feature? (no)

@geniusjoe
geniusjoe force-pushed the dev/ProducerBlockedQuotaExceededException branch 2 times, most recently from 4de6a9f to 2c6d942 Compare January 20, 2026 15:29
@geniusjoe
geniusjoe force-pushed the dev/ProducerBlockedQuotaExceededException branch from 2c6d942 to c5c3ffd Compare January 29, 2026 15:33
@RobertIndie
RobertIndie requested a review from Copilot January 30, 2026 07:46
@RobertIndie RobertIndie added this to the v0.19.0 milestone Jan 30, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This pull request modifies the producer's reconnection behavior when encountering a ProducerBlockedQuotaExceededException. The change aligns the Go client with the Java client by treating this exception as retryable, allowing the producer to continue reconnecting after failing pending messages rather than closing the producer entirely.

Changes:

  • Modified producer_partition.go to remove early return when ProducerBlockedQuotaExceededException is encountered, allowing reconnection to continue
  • Added test TestProducerReconnectWhenBacklogQuotaExceed to verify the reconnection behavior
  • Updated golangci-lint version from v1.61.0 to v1.64.2

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 6 comments.

File Description
pulsar/producer_partition.go Removed early return for ProducerBlockedQuotaExceededException to allow reconnection retry
pulsar/producer_test.go Added test and custom backoff policy implementation to verify quota exceeded reconnection behavior
Makefile Updated golangci-lint version to v1.64.2

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_partition.go Resolved
Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved

@RobertIndie RobertIndie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PTAL comments from copilot. Thanks.

Comment thread pulsar/producer_test.go Resolved
@geniusjoe
geniusjoe force-pushed the dev/ProducerBlockedQuotaExceededException branch 2 times, most recently from de206e1 to 70d6b0b Compare January 30, 2026 13:05
@RobertIndie
RobertIndie requested a review from Copilot February 6, 2026 09:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pulsar/producer_test.go Resolved
Comment thread Makefile Resolved
Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved
@geniusjoe
geniusjoe force-pushed the dev/ProducerBlockedQuotaExceededException branch from 70d6b0b to 1c5c317 Compare February 6, 2026 10:16
@RobertIndie
RobertIndie merged commit d7fafb5 into apache:master Mar 20, 2026
11 of 12 checks passed
@RobertIndie RobertIndie changed the title [Issue 1128][Producer] Regard ProducerBlockedQuotaExceededException as a retryable exception for reconnecting feat: regard ProducerBlockedQuotaExceededException as retryable exception to continue to reconnect Mar 20, 2026
sre-ci-robot pushed a commit to milvus-io/milvus that referenced this pull request May 20, 2026
…49933)

## Summary

Bumps `pulsar-client-go` v0.17.0 → v0.19.0 to pick up

[apache/pulsar-client-go#1457](apache/pulsar-client-go#1457):
the client used to give up reconnecting after a topic hit the
`producer_exception` backlog quota, leaving the producer permanently
dead and writes timing out forever. v0.19.0 treats the quota exception
as retryable, so producers recover once backlog clears.

The bump can't ship alone: it's blocked at the module graph by Milvus's
pinned `xiaofan-luan/pulsarctl v0.5.1` fork, which imports
`pulsar-client-go/oauth2/store` — a package v0.19.0 has removed. MVS
then pulls the legacy standalone `pulsar-client-go/oauth2` module back
in, which collides with the main module's `oauth2/clock` (ambiguous
import). To unblock cleanly, this PR also replaces the only ~50 lines
of pulsarctl admin usage in Milvus with `pulsar-client-go`'s own
`pulsaradmin` package (shipped in the same module). The legacy
`99designs/{keyring,go-keychain}` and `danieljoos/wincred` transitive
deps fall out as a side effect.

## Changes

**Source (2 files, ~20 lines net)**

- `pkg/mq/msgstream/mqwrapper/pulsar/pulsar_client.go` —
`NewAdminClient` now returns `admin.Client` from
`pulsaradmin/pkg/admin`,
  built from `config.Config` instead of `common.Config`.
- `pkg/mq/msgstream/mq_factory.go` —
`Subscriptions().Delete(*topic, sub, true)` → `ForceDelete(*topic, sub)`
  (pulsaradmin splits force-delete into its own method);
  error type assertion `cli.Error` → `rest.Error` (same `Reason` field).

**Module hygiene (`pkg/go.mod`, `go.mod`)**

- bump `apache/pulsar-client-go` v0.17.0 → v0.19.0
- drop `require github.com/streamnative/pulsarctl`
- drop `replace streamnative/pulsarctl => xiaofan-luan/pulsarctl v0.5.1`
- drop `exclude pulsar-client-go/oauth2 v0.0.0-20211108044248-...`
  (no longer needed; the standalone oauth2 module is no longer in the
  graph at all — `go list -m .../oauth2` ⇒ *not a known dependency*)

## Behavior notes

v0.19.0 still calls `failPendingMessages` each time the producer
reconnect hits the quota, so in-flight sends continue to fail with
`ErrProducerBlockedQuotaExceeded` — upper-layer (msgstream / WAL) error
surface is **unchanged**. What changes is that the producer no longer
permanently dies and recovers automatically once backlog clears.

API surface diff verified against Milvus's pulsar usage: no removed or
renamed symbols; option structs only additively changed
(`ConsumerOptions.NackPrecisionBit` added). v0.19.0 requires `go 1.24`;
Milvus is on `go 1.25.8` — no Go version gate.

issue: #49932

## Test plan

- [x] `go build ./...` in `pkg/` clean (with rocksdb pkg-config)
- [x] `go vet -tags dynamic,test` clean on msgstream +
walimpls/impls/pulsar
- [x] pulsar test code compiles under `-tags dynamic,test
-gcflags="all=-N -l"`
- [x] Non-broker unit tests pass: `TestPulsarID_Serialize`,
`TestPulsarID_Equal`
- [x] `go list -m .../pulsar-client-go/oauth2` ⇒ `not a known
dependency`
      (ambiguous-import root cause structurally resolved)
- [ ] CI green
- [ ] Broker-dependent unit tests pass against Pulsar 3.0.2 (matches
      milvus-helm `pulsarv3` subchart)
- [ ] Pre-merge: induce `producer_exception` backlog quota in a staging
      cluster; verify producer recovers after backlog clears
      (independent reproduction already done out-of-tree)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Signed-off-by: zhenshan.cao <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants