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/04/21 16:03:24 UTC
(pulsar) branch branch-3.0 updated (b85afe9bd0a -> b7750140a7c)
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a change to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
from b85afe9bd0a [fix][build][branch-3.0] Fix trino license file
new 0aa4dca430c [fix][client] Fail messages immediately in ProducerImpl when in terminal state (#25317)
new 90ef622e882 [improve][broker] Close connection when close consumer write fails (#25520)
new b7750140a7c [fix][build][branch-3.0] Fix trino license
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../apache/pulsar/broker/service/ServerCnx.java | 13 ++++++-
.../pulsar/broker/service/ServerCnxTest.java | 41 +++++++++++++++++++---
.../broker/service/TopicTerminationTest.java | 3 +-
.../apache/pulsar/client/impl/ProducerImpl.java | 30 +++++++++++++++-
.../pulsar/common/protocol/PulsarHandler.java | 3 +-
pulsar-sql/presto-distribution/LICENSE | 2 +-
6 files changed, 83 insertions(+), 9 deletions(-)
(pulsar) 02/03: [improve][broker] Close connection when close consumer write fails (#25520)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 90ef622e882c28e539cde440c1c94bc54642c5ef
Author: Zixuan Liu <no...@gmail.com>
AuthorDate: Wed Apr 15 10:45:02 2026 +0800
[improve][broker] Close connection when close consumer write fails (#25520)
(cherry picked from commit f688ff748fe49d06ffa0829ce61d51707584f712)
---
.../apache/pulsar/broker/service/ServerCnx.java | 13 ++++++-
.../pulsar/broker/service/ServerCnxTest.java | 41 +++++++++++++++++++---
.../pulsar/common/protocol/PulsarHandler.java | 3 +-
3 files changed, 51 insertions(+), 6 deletions(-)
diff --git a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
index 09fa3d37661..103f1820f10 100644
--- a/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
+++ b/pulsar-broker/src/main/java/org/apache/pulsar/broker/service/ServerCnx.java
@@ -3141,12 +3141,23 @@ public class ServerCnx extends PulsarHandler implements TransportCnx {
// removes consumer-connection from map and send close command to consumer
safelyRemoveConsumer(consumer);
if (getRemoteEndpointProtocolVersion() >= v5.getValue()) {
- writeAndFlush(Commands.newCloseConsumer(consumer.consumerId(), -1L));
+ writeCloseConsumerAndCloseConnectionOnFailure(Commands.newCloseConsumer(consumer.consumerId(), -1L),
+ consumer.consumerId());
} else {
close();
}
}
+ private void writeCloseConsumerAndCloseConnectionOnFailure(ByteBuf cmd, long consumerId) {
+ ctx.writeAndFlush(cmd).addListener(future -> {
+ if (!future.isSuccess()) {
+ log.warn("[{}] Forcing connection to close since cannot send close consumer command for consumer {}",
+ remoteAddress, consumerId, future.cause());
+ close();
+ }
+ });
+ }
+
/**
* It closes the connection with client which triggers {@code channelInactive()} which clears all producers and
* consumers from connection-map.
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
index b4f0a1d4935..4f69a2c9a1d 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/ServerCnxTest.java
@@ -45,10 +45,14 @@ import static org.testng.Assert.assertNull;
import static org.testng.Assert.assertTrue;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
+import io.netty.channel.ChannelFuture;
import io.netty.channel.ChannelHandler;
+import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.DefaultChannelId;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
+import io.netty.util.concurrent.Future;
+import io.netty.util.concurrent.GenericFutureListener;
import io.vertx.core.impl.ConcurrentHashSet;
import java.io.Closeable;
import java.io.IOException;
@@ -88,15 +92,14 @@ import org.apache.bookkeeper.mledger.impl.PositionImpl;
import org.apache.commons.lang3.mutable.MutableInt;
import org.apache.pulsar.broker.PulsarService;
import org.apache.pulsar.broker.ServiceConfiguration;
+import org.apache.pulsar.broker.TransactionMetadataStoreService;
import org.apache.pulsar.broker.auth.MockAlwaysExpiredAuthenticationProvider;
+import org.apache.pulsar.broker.auth.MockAuthenticationProvider;
import org.apache.pulsar.broker.auth.MockAuthorizationProvider;
+import org.apache.pulsar.broker.auth.MockMultiStageAuthenticationProvider;
import org.apache.pulsar.broker.auth.MockMutableAuthenticationProvider;
import org.apache.pulsar.broker.authentication.AuthenticationDataSource;
import org.apache.pulsar.broker.authentication.AuthenticationDataSubscription;
-import org.apache.pulsar.broker.testcontext.PulsarTestContext;
-import org.apache.pulsar.broker.TransactionMetadataStoreService;
-import org.apache.pulsar.broker.auth.MockAuthenticationProvider;
-import org.apache.pulsar.broker.auth.MockMultiStageAuthenticationProvider;
import org.apache.pulsar.broker.authentication.AuthenticationProvider;
import org.apache.pulsar.broker.authentication.AuthenticationService;
import org.apache.pulsar.broker.authentication.AuthenticationState;
@@ -108,6 +111,7 @@ import org.apache.pulsar.broker.service.BrokerServiceException.ServiceUnitNotRea
import org.apache.pulsar.broker.service.ServerCnx.State;
import org.apache.pulsar.broker.service.persistent.PersistentTopic;
import org.apache.pulsar.broker.service.utils.ClientChannelHelper;
+import org.apache.pulsar.broker.testcontext.PulsarTestContext;
import org.apache.pulsar.client.api.ProducerAccessMode;
import org.apache.pulsar.client.api.transaction.TxnID;
import org.apache.pulsar.client.util.ConsumerName;
@@ -2468,6 +2472,35 @@ public class ServerCnxTest {
channel.finish();
}
+ @Test
+ public void testCloseConsumerClosesConnectionWhenWriteFails() throws Exception {
+ resetChannel();
+ setChannelConnected();
+
+ var ctx = mock(ChannelHandlerContext.class);
+ var writeFuture = mock(ChannelFuture.class);
+ var writeFailure = new RuntimeException("close consumer write failed");
+ when(ctx.writeAndFlush(any())).thenReturn(writeFuture);
+ when(writeFuture.isSuccess()).thenReturn(false);
+ when(writeFuture.cause()).thenReturn(writeFailure);
+ when(writeFuture.addListener(any())).thenAnswer(invocation -> {
+ GenericFutureListener<Future<? super Void>> listener = invocation.getArgument(0);
+ listener.operationComplete(writeFuture);
+ return writeFuture;
+ });
+ serverCnx.setCtx(ctx);
+
+ var consumer = mock(Consumer.class);
+ when(consumer.consumerId()).thenReturn(1L);
+
+ serverCnx.setRemoteEndpointProtocolVersion(ProtocolVersion.v12.getValue());
+
+ serverCnx.closeConsumer(consumer);
+
+ verify(ctx).writeAndFlush(any());
+ verify(ctx).close();
+ }
+
@Test(timeOut = 30000)
public void testSubscribeCommand() throws Exception {
final String failSubName = "failSub";
diff --git a/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarHandler.java b/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarHandler.java
index 020b753086f..00fbe9d8baa 100644
--- a/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarHandler.java
+++ b/pulsar-common/src/main/java/org/apache/pulsar/common/protocol/PulsarHandler.java
@@ -52,7 +52,8 @@ public abstract class PulsarHandler extends PulsarDecoder {
return remoteEndpointProtocolVersion;
}
- protected void setRemoteEndpointProtocolVersion(int remoteEndpointProtocolVersion) {
+ @VisibleForTesting
+ public void setRemoteEndpointProtocolVersion(int remoteEndpointProtocolVersion) {
this.remoteEndpointProtocolVersion = remoteEndpointProtocolVersion;
}
(pulsar) 01/03: [fix][client] Fail messages immediately in ProducerImpl when in terminal state (#25317)
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit 0aa4dca430c204458e1d2d72010c156a69776e7a
Author: Matteo Merli <mm...@apache.org>
AuthorDate: Mon Mar 16 00:23:17 2026 -0700
[fix][client] Fail messages immediately in ProducerImpl when in terminal state (#25317)
(cherry picked from commit 1b5c818a538ee2cbcc88a4d3b4955eeb07a7d586)
---
.../broker/service/TopicTerminationTest.java | 3 ++-
.../apache/pulsar/client/impl/ProducerImpl.java | 30 +++++++++++++++++++++-
2 files changed, 31 insertions(+), 2 deletions(-)
diff --git a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicTerminationTest.java b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicTerminationTest.java
index 4229c4fc16b..83a6cd1c6ad 100644
--- a/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicTerminationTest.java
+++ b/pulsar-broker/src/test/java/org/apache/pulsar/broker/service/TopicTerminationTest.java
@@ -141,6 +141,7 @@ public class TopicTerminationTest extends BrokerTestBase {
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName)
.enableBatching(false)
.messageRoutingMode(MessageRoutingMode.SinglePartition)
+ .sendTimeout(5, TimeUnit.SECONDS)
.create();
CyclicBarrier barrier = new CyclicBarrier(2);
@@ -169,7 +170,7 @@ public class TopicTerminationTest extends BrokerTestBase {
boolean alreadyFailed = false;
try {
- FutureUtil.waitForAll(futures).get();
+ FutureUtil.waitForAll(futures).get(10, TimeUnit.SECONDS);
} catch (Exception e) {
// Ignore for now, check is below
}
diff --git a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
index c001d8f8ba5..909b0fcf7c2 100644
--- a/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
+++ b/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ProducerImpl.java
@@ -992,6 +992,23 @@ public class ProducerImpl<T> extends ProducerBase<T> implements TimerTask, Conne
}
}
+ private PulsarClientException getTerminalException(State state) {
+ switch (state) {
+ case Terminated:
+ return new PulsarClientException.TopicTerminatedException(
+ format("The topic %s that the producer %s produces to has been terminated", topic,
+ producerName));
+ case Closed:
+ return new PulsarClientException.AlreadyClosedException(
+ format("The producer %s of the topic %s was already closed", producerName, topic));
+ case ProducerFenced:
+ return new PulsarClientException.ProducerFencedException(
+ format("The producer %s of the topic %s was fenced", producerName, topic));
+ default:
+ return new PulsarClientException.NotConnectedException();
+ }
+ }
+
private boolean isValidProducerState(SendCallback callback, long sequenceId) {
switch (getState()) {
case Ready:
@@ -2371,9 +2388,20 @@ public class ProducerImpl<T> extends ProducerBase<T> implements TimerTask, Conne
op.cmd.release();
return;
}
+ final State state = getState();
+ if (state == State.Terminated || state == State.Closed || state == State.ProducerFenced) {
+ // The producer is in a terminal state and will never reconnect. Fail the message immediately
+ // rather than leaving it stuck in pendingMessages until sendTimeout.
+ releaseSemaphoreForSendOp(op);
+ client.getMemoryLimitController().releaseMemory(op.uncompressedSize);
+ op.sendComplete(getTerminalException(state));
+ ReferenceCountUtil.safeRelease(op.cmd);
+ op.recycle();
+ return;
+ }
pendingMessages.add(op);
updateLastSeqPushed(op);
- if (State.RegisteringSchema.equals(getState())) {
+ if (State.RegisteringSchema.equals(state)) {
// Since there is a in-progress schema registration, do not continuously publish to avoid break publish
// ordering. After the schema registration finished, it will trigger a "recoverProcessOpSendMsgFrom" to
// publish all messages in "pendingMessages".
(pulsar) 03/03: [fix][build][branch-3.0] Fix trino license
Posted by lh...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
lhotari pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/pulsar.git
commit b7750140a7c9c1bbf28b2693296cae5e752cc4fe
Author: Lari Hotari <lh...@apache.org>
AuthorDate: Tue Apr 21 19:00:18 2026 +0300
[fix][build][branch-3.0] Fix trino license
---
pulsar-sql/presto-distribution/LICENSE | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/pulsar-sql/presto-distribution/LICENSE b/pulsar-sql/presto-distribution/LICENSE
index 460d9aebead..7be45480854 100644
--- a/pulsar-sql/presto-distribution/LICENSE
+++ b/pulsar-sql/presto-distribution/LICENSE
@@ -578,7 +578,7 @@ Public Domain (CC0) -- licenses/LICENSE-CC0.txt
* AOP Alliance
- aopalliance-1.0.jar
* Reactive Streams
- - reactive-streams-1.0.4.jar
+ - reactive-streams-1.0.3.jar
Creative Commons Attribution License
* Jcip -- licenses/LICENSE-jcip.txt