Skip to content

[client] Fix issue where paused consumer receives new message when reconnecting #8165

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

Merged
merged 1 commit into from
Oct 2, 2020

Conversation

massakam
Copy link
Contributor

Motivation

Consumers whose pause() method is called are expected not to fetch any more new messages from the broker until resume() is called. However, when the topic is unloaded or the broker is restarted, the consumer receives new messages.

While the consumer is paused, no flow permits are sent to the broker when the increaseAvailablePermits() method is called.

protected void increaseAvailablePermits(ClientCnx currentCnx, int delta) {
int available = AVAILABLE_PERMITS_UPDATER.addAndGet(this, delta);
while (available >= receiverQueueRefillThreshold && !paused) {
if (AVAILABLE_PERMITS_UPDATER.compareAndSet(this, available, 0)) {
sendFlowPermitsToBroker(currentCnx, available);
break;
} else {
available = AVAILABLE_PERMITS_UPDATER.get(this);
}
}
}

However, if the sendFlowPermitsToBroker() method is called directly, flow permits will be sent even while the consumer is paused. When a reconnection occurs, sendFlowPermitsToBroker() is called instead of increaseAvailablePermits().

// if the consumer is not partitioned or is re-connected and is partitioned, we send the flow
// command to receive messages.
// For readers too (isDurable==false), the partition idx will be set though we have to
// send available permits immediately after establishing the reader session
if (!(firstTimeConnect && hasParentConsumer && isDurable) && conf.getReceiverQueueSize() != 0) {
sendFlowPermitsToBroker(cnx, conf.getReceiverQueueSize());
}

Modifications

Fixed consumer classes to always use increaseAvailablePermits() instead of sendFlowPermitsToBroker().

@massakam massakam added type/bug The PR fixed a bug or issue reported a bug area/client release/2.6.2 labels Sep 30, 2020
@massakam massakam added this to the 2.7.0 milestone Sep 30, 2020
@massakam massakam self-assigned this Sep 30, 2020
@sijie sijie merged commit 4c489be into apache:master Oct 2, 2020
lbenc135 pushed a commit to lbenc135/pulsar that referenced this pull request Oct 3, 2020
apache#8165)

### Motivation

Consumers whose `pause()` method is called are expected not to fetch any more new messages from the broker until `resume()` is called. However, when the topic is unloaded or the broker is restarted, the consumer receives new messages.

While the consumer is paused, no flow permits are sent to the broker when the `increaseAvailablePermits()` method is called.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1527-L1538

However, if the `sendFlowPermitsToBroker()` method is called directly, flow permits will be sent even while the consumer is paused. When a reconnection occurs, `sendFlowPermitsToBroker()` is called instead of `increaseAvailablePermits()`.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L850-L856

### Modifications

Fixed consumer classes to always use `increaseAvailablePermits()` instead of `sendFlowPermitsToBroker()`.
@massakam massakam deleted the fix-pause branch October 28, 2020 03:34
wolfstudy pushed a commit that referenced this pull request Oct 30, 2020
#8165)

### Motivation

Consumers whose `pause()` method is called are expected not to fetch any more new messages from the broker until `resume()` is called. However, when the topic is unloaded or the broker is restarted, the consumer receives new messages.

While the consumer is paused, no flow permits are sent to the broker when the `increaseAvailablePermits()` method is called.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1527-L1538

However, if the `sendFlowPermitsToBroker()` method is called directly, flow permits will be sent even while the consumer is paused. When a reconnection occurs, `sendFlowPermitsToBroker()` is called instead of `increaseAvailablePermits()`.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L850-L856

### Modifications

Fixed consumer classes to always use `increaseAvailablePermits()` instead of `sendFlowPermitsToBroker()`.

(cherry picked from commit 4c489be)
huangdx0726 pushed a commit to huangdx0726/pulsar that referenced this pull request Nov 13, 2020
apache#8165)

### Motivation

Consumers whose `pause()` method is called are expected not to fetch any more new messages from the broker until `resume()` is called. However, when the topic is unloaded or the broker is restarted, the consumer receives new messages.

While the consumer is paused, no flow permits are sent to the broker when the `increaseAvailablePermits()` method is called.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L1527-L1538

However, if the `sendFlowPermitsToBroker()` method is called directly, flow permits will be sent even while the consumer is paused. When a reconnection occurs, `sendFlowPermitsToBroker()` is called instead of `increaseAvailablePermits()`.
https://github.com/apache/pulsar/blob/dea574b3c6af7ea8eaa4904d8d6ed1044df00642/pulsar-client/src/main/java/org/apache/pulsar/client/impl/ConsumerImpl.java#L850-L856

### Modifications

Fixed consumer classes to always use `increaseAvailablePermits()` instead of `sendFlowPermitsToBroker()`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client release/2.6.2 type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants