You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by zi...@apache.org on 2026/07/21 08:25:15 UTC
(pulsar-client-go) branch master updated: fix: avoid infinite retry in blue-green migration test (#1502)
This is an automated email from the ASF dual-hosted git repository.
nodece pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-client-go.git
The following commit(s) were added to refs/heads/master by this push:
new b3d8930e fix: avoid infinite retry in blue-green migration test (#1502)
b3d8930e is described below
commit b3d8930e4ac789e9d52b474a85bba71e26142cf2
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Tue Jul 21 16:25:10 2026 +0800
fix: avoid infinite retry in blue-green migration test (#1502)
* fix: avoid context leak in blue-green migration test
Co-authored-by: Copilot <22...@users.noreply.github.com>
* fix: avoid infinite retry in blue-green migration test
Co-authored-by: Copilot <22...@users.noreply.github.com>
* Address comment
* Address comment
---------
Co-authored-by: Copilot <22...@users.noreply.github.com>
---
pulsar/blue_green_migration_test.go | 68 +++++++++++++++++++++++++++++++++----
1 file changed, 62 insertions(+), 6 deletions(-)
diff --git a/pulsar/blue_green_migration_test.go b/pulsar/blue_green_migration_test.go
index 4cd2e476..5c0f5af4 100644
--- a/pulsar/blue_green_migration_test.go
+++ b/pulsar/blue_green_migration_test.go
@@ -21,6 +21,7 @@ package pulsar
import (
"context"
+ "errors"
"fmt"
"net/http"
"runtime"
@@ -148,6 +149,7 @@ func testTopicMigrate(
// Signals both producer and consumer have processed `messageCountBeforeUnload` messages
wgSendAndReceiveMessages := sync.WaitGroup{}
wgSendAndReceiveMessages.Add(2)
+ errCh := make(chan error, 1)
// Producer
go func() {
@@ -159,14 +161,32 @@ func testTopicMigrate(
}
pm := ProducerMessage{Payload: []byte(fmt.Sprintf("hello-%d", i))}
+ retryStarted := time.Now()
for true {
- ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
- defer cancel()
- _, err := producer.Send(ctx, &pm)
+ err := func() error {
+ ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
+ defer cancel()
+ _, err := producer.Send(ctx, &pm)
+ return err
+ }()
if err == nil {
break
}
+ if errors.Is(err, ErrTopicTerminated) || errors.Is(err, ErrProducerClosed) {
+ select {
+ case errCh <- fmt.Errorf("producer became terminal during migration at message %d: %w", i, err):
+ default:
+ }
+ return
+ }
+ if time.Since(retryStarted) > 30*time.Second {
+ select {
+ case errCh <- fmt.Errorf("producer send retry exceeded 30s at message %d: %w", i, err):
+ default:
+ }
+ return
+ }
time.Sleep(1000 * time.Millisecond)
}
@@ -185,16 +205,24 @@ func testTopicMigrate(
wgUnload.Wait()
}
+ retryStarted := time.Now()
for true {
ctx, cancel := context.WithTimeout(context.Background(), 1*time.Second)
- defer cancel()
m, err := consumer.Receive(ctx)
+ cancel()
if err == nil {
err = consumer.Ack(m)
if err == nil {
break
}
}
+ if time.Since(retryStarted) > 30*time.Second {
+ select {
+ case errCh <- fmt.Errorf("consumer receive/ack retry exceeded 30s at message %d: %w", i, err):
+ default:
+ }
+ return
+ }
time.Sleep(100 * time.Millisecond)
}
@@ -205,7 +233,33 @@ func testTopicMigrate(
}()
// Unload the bundle, triggering the producers and consumers to reconnect to the specified broker.
- wgSendAndReceiveMessages.Wait()
+ waitWithError := func(wg *sync.WaitGroup, stage string) bool {
+ doneCh := make(chan struct{})
+ go func() {
+ wg.Wait()
+ close(doneCh)
+ }()
+
+ select {
+ case <-doneCh:
+ select {
+ case err := <-errCh:
+ req.NoError(err, stage)
+ return false
+ default:
+ }
+ return true
+ case err := <-errCh:
+ req.NoError(err, stage)
+ return false
+ case <-time.After(90 * time.Second):
+ req.FailNow(stage + " timeout")
+ return false
+ }
+ }
+ if !waitWithError(&wgSendAndReceiveMessages, "waiting for pre-unload send/receive") {
+ return
+ }
topicMigrationURL = fmt.Sprintf(
"/admin/v2/clusters/%s/migrate?migrated=true", cluster)
@@ -248,5 +302,7 @@ func testTopicMigrate(
return req.Equal(dstTopicBrokerURL, topicBrokerURL)
})
- wgRoutines.Wait()
+ if !waitWithError(&wgRoutines, "waiting for producer/consumer routines") {
+ return
+ }
}