-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] consumer.pause() is paused after 1 message is consumed even with receiverQueueSize=0 #19320
Comments
@Croway - thanks for opening the issue. I was not able to reproduce it on tag @Test(timeOut = 30000L)
public void zeroQueueSizePausedConsumer() throws PulsarClientException {
String key = "zeroQueueSizePausedConsumer";
// 1. Config
final String topicName = "persistent://prop/use/ns-abc/topic-" + key;
final String subscriptionName = "my-ex-subscription-" + key;
final String messagePredicate = "my-message-" + key + "-";
// 2. Create Producer
Producer<byte[]> producer = pulsarClient.newProducer().topic(topicName).enableBatching(false).create();
// 3. Create Consumer
ConsumerImpl<byte[]> consumer = (ConsumerImpl<byte[]>) pulsarClient.newConsumer().topic(topicName)
.subscriptionName(subscriptionName).receiverQueueSize(0).subscribe();
consumer.pause();
// 3. producer publish messages
for (int i = 0; i < 2; i++) {
String message = messagePredicate + i;
log.info("Producer produced: " + message);
producer.send(message.getBytes());
}
// 4. Receiver receives the message
Message<byte[]> message;
for (int i = 0; i < totalMessages; i++) {
assertEquals(consumer.numMessagesInQueue(), 0);
message = consumer.receive();
assertEquals(new String(message.getData()), messagePredicate + i);
assertEquals(consumer.numMessagesInQueue(), 0);
log.info("Consumer received : " + new String(message.getData()));
}
} When I run that test, it fails due to the 30 second timeout. Additionally, I tested with |
Hello @nicoloboschi, @michaeljmarshall, I created a reproducer https://github.com/Croway/pulsar-client-test since I noticed the reproducer step was not good enough, actually, this is the original failing test https://github.com/apache/camel/blob/main/components/camel-pulsar/src/test/java/org/apache/camel/component/pulsar/integration/PulsarSuspendRouteIT.java#L220 , I just removed the camel overhead, the logic should be the same, the test fails with 2.11.0 and pass with 2.10.3 |
Thanks for the reproducer @Croway. I reproduced it on my end. I'll work on a fix. |
After digging into the reproducer, I found an explanation for the behavior. The difference between 2.10.3 and 2.11.0 is because we stopped wrapping single messages in batch message envelopes as of PIP 189 #16619, which was introduced in 2.11.0. In the 2.10.3 test, note that the logs contain this log line:
In the 2.11.0 test, we do not log this exception because the message is a single message. A few notes:
@Croway - I think it the underlying issue is that the test described in https://issues.apache.org/jira/projects/CAMEL/issues/CAMEL-18974 was implicitly relying on the zero queue failing due to message batching, and the test would have failed if the producer had not batched the message. It might be the case that the test needs to improve. |
Anecdotally, we do have a unit test to verify the behavior I described above: pulsar/pulsar-broker/src/test/java/org/apache/pulsar/client/impl/ZeroQueueSizeTest.java Lines 423 to 456 in d03d28e
In that test, the consumer uses a listener, but the semantics are the same:
|
Thanks a lot for the explanation @michaeljmarshall , I've updated our test so that it reflects yours. Thanks for the analysis and sorry for bothering. |
Search before asking
Version
Fedora, 2.11.0
Minimal reproduce step
What did you expect to see?
0 messages consumed
What did you see instead?
1 message consumed
Anything else?
With pulsar-client version 2.10.3 and pulsar-client-admin version 2.10.3 the reproducer works, something changed in the client.
Are you willing to submit a PR?
The text was updated successfully, but these errors were encountered: