You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by lh...@apache.org on 2026/09/23 08:33:59 UTC

(pulsar) 20/27: [fix][client] Drop a send receipt for a removed producer, not the connection (#26618)

This is an automated email from the ASF dual-hosted git repository.

lhotari pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/pulsar.git

commit d63678a4d9dd9210f81c2e343db80895d9f88e66
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Wed Sep 16 22:46:29 2026 -0700

    [fix][client] Drop a send receipt for a removed producer, not the connection (#26618)
    
    (cherry picked from commit 4315708040d9b5113d652359db724c2bf55c58ea)
---
 .../org/apache/pulsar/client/impl/ClientCnx.java   |  2 +-
 .../apache/pulsar/client/impl/ClientCnxTest.java   | 27 ++++++++++++++++++++++
 2 files changed, 28 insertions(+), 1 deletion(-)

diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
index dc73f435c7f4..ee97e66df488 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ClientCnx.java
@@ -502,7 +502,7 @@ public class ClientCnx extends PulsarHandler {
                 producer.printWarnLogWhenCanNotDetermineDeduplication(ctx.channel(), sequenceId, highestSequenceId);
             }
 
-        } else {
+        } else if (producer != null) {
             if (log.isDebugEnabled()) {
                 log.debug("{} Got receipt for producer: [id:{}, name:{}] -- sequence-id: {}-{} -- entry-id: {}:{}",
                         ctx.channel(), producerId, producer.getProducerName(), sequenceId, highestSequenceId,
diff --git a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
index 20de6eacf55b..2bd862e343d6 100644
--- a/pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
+++ b/pulsar-client/src/test/java/org/apache/pulsar/client/impl/ClientCnxTest.java
@@ -48,6 +48,7 @@ import org.apache.pulsar.common.api.proto.CommandCloseProducer;
 import org.apache.pulsar.common.api.proto.CommandConnected;
 import org.apache.pulsar.common.api.proto.CommandError;
 import org.apache.pulsar.common.api.proto.CommandLookupTopicResponse;
+import org.apache.pulsar.common.api.proto.CommandSendReceipt;
 import org.apache.pulsar.common.api.proto.CommandWatchTopicListSuccess;
 import org.apache.pulsar.common.api.proto.CommandWatchTopicUpdate;
 import org.apache.pulsar.common.api.proto.ServerError;
@@ -292,6 +293,32 @@ public class ClientCnxTest {
         eventLoop.shutdownGracefully();
     }
 
+    @Test
+    public void testSendReceiptForRemovedProducerIsIgnored() {
+        ThreadFactory threadFactory = new DefaultThreadFactory("testSendReceiptForRemovedProducerIsIgnored");
+        EventLoopGroup eventLoop = EventLoopUtil.newEventLoopGroup(1, false, threadFactory);
+        ClientConfigurationData conf = new ClientConfigurationData();
+        ClientCnx cnx = new ClientCnx(InstrumentProvider.NOOP, conf, eventLoop);
+        cnx.state = ClientCnx.State.Ready;
+
+        // A receipt for a producer the broker has already told the client to close, as happens when
+        // its topic is terminated with sends in flight, is dropped rather than failing the connection.
+        long producerId = 1;
+        CommandSendReceipt receipt = new CommandSendReceipt()
+                .setProducerId(producerId)
+                .setSequenceId(5)
+                .setHighestSequenceId(5);
+        receipt.setMessageId().setLedgerId(3).setEntryId(7);
+        cnx.handleSendReceipt(receipt);
+
+        ProducerImpl<?> producer = mock(ProducerImpl.class);
+        cnx.registerProducer(producerId, producer);
+        cnx.handleSendReceipt(receipt);
+        verify(producer).ackReceived(cnx, 5, 5, 3, 7);
+
+        eventLoop.shutdownGracefully();
+    }
+
     @Test
     public void testIdleCheckWithTopicListWatcher() {
         ClientCnx cnx =