You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Catastrophic frequent random subscription freezes, especially on high-traffic topics. #6054
Describe the bug
Topics randomly freeze, causing catastrophic topic outages on a weekly (or more frequent) basis. This has been an issue as long as my team has used Pulsar, and it's been communicated to a number of folks on the Pulsar PMC committee.
(I thought an issue was already created for this bug, but I couldn't find it anywhere.)
To Reproduce
We have not figured out how to reproduce the issue. It's random (seems to be non-deterministic) and doesn't seem to have any clues in the broker logs.
Expected behavior
Topics should never just randomly stop working to where the only resolution is restarting the problem broker.
Steps to Diagnose and Temporarily Resolve Step 2: Check the rate out on the topic. (click on the topic in the dashboard, or do a stats on the topic and look at the "msgRateOut")
If the rate out is 0 this is likely a frozen topic, but to verify do the following:
In the pulsar dashboard, click on the broker that topic is living on. If you see that there are multiple topic that have a rate out of 0, then proceed to the next step, if not it could potentially be another issue. Investigate further.
Step 3: Stop the broker on the server that the topic is living on. pulsar-broker stop .
Step 4: Wait for the backlog to be consumed and all the functions to be rescheduled. (typically wait for about 5-10 mins)
Environment:
Docker on bare metal running: `apachepulsar/pulsar-all:2.4.0`
on CentOS.
Brokers are the function workers.
This has been an issue with previous versions of Pulsar as well.
Additional context
Problem was MUCH worse with Pulsar 2.4.2, so our team needed to roll back to 2.4.0 (which has the problem, but it's less frequent).
This is preventing the team from progressing in the use of Pulsar, and it's causing SLA problems with those who use our service.
FWIW, @devinbost I am suspicious of the netty version in the 2.4.X stream. There is a know memory usage issue (netty/netty#8814) in the 4.1.32 version of netty that is used in the stream. When I was testing, I would see issues like you are describing. Then I patched in the latest version of netty, and things seemed better. I have been running with a patched 2.4.2 for a while and have not seen any issues. You may be experiencing something completely different, but it might be worth trying 2.4.2 + latest netty.
I noticed that each topic lives on a single broker, which creates a single point of failure.
Is there any interest in making topics higher availability? (I suppose it would be a workaround, but it might help prevent other issues.)
I noticed that each topic lives on a single broker, which creates a single point of failure.
Is there any interest in making topics higher availability?
We (StreamNative) have been helping folks from Tencent at developing a feature called ReadOnly brokers. It allows a topic can have multiple owners (one writeable owner and multiple readonly owners). It has been running on production for a while. They will contribute it back soon.
Is there anything in particular that we should look for regarding permits?
Incorrect permits has been one of the main reasons causing the consumer to be stalled. You can use "unload" command to unload a topic or a namespace bundle to trigger a consumer reconnect. It resets the consumer state to mitigate the problem.
I am not sure if your problem is related to permits. but if the same problem occurs, the first thing you should do is to use topic stats or topic stats-internal to get the stats or internal stats of a topic.
We will need to capture some stats when this happens next. After my team made some changes to improve the stability of the Zookeeper cluster, the frequency of this issue decreased on v2.4.0. So, we will need to update one of the clusters to use 2.4.2 to reproduce this issue again.
I also noticed that some of the bookkeeper nodes are currently running: apachepulsar/pulsar-all:2.3.0
and some of them are running: streamlio/pulsar-all:2.4.0-streamlio-24
I don't know if that would have anything to do with the issue.
I have reported a separate issue about a direct memory leak, it's #10738 . It includes a full repro case with a helm deployment that can be used to reproduce the issue in minikube (requires sufficient RAM) (or any k8s environment).
What are your broker.conf settings? And, how many messages are you
processing? We've noticed that some settings increase the frequency of
this, but I'm still working on investigating the root cause.
Something is causing the broker to not ack messages, but we're not sure
about the exact cause yet.
--
Devin G. Bost
I mapped out more of the ack flow, so I will add it to what I documented here and make it more readable.
The bracket notation below is intended to specify an instance of the class (to distinguish from a static method call.)
When ProducerImpl sends the messages, it builds newSend command instances,
which get picked up by ServerCnx.handleSend(..),
which goes to Producer.publishMessage(..),
then PersistentTopic.publishMessage(..)
which calls asyncAddEntry(headersAndPayload, publishContext),
which calls [PersistentTopic].ledger.asyncAddEntry(headersAndPayload, (int) publishContext.getNumberOfMessages(), this, publishContext)
which creates the OpAddEntry and calls internalAsyncAddEntry(addOperation) on a different thread,
which adds OpAddEntry to [ManagedLedgerImpl].pendingAddEntries
From somewhere (it's not clear to me exactly where yet) we call OpAddEntry.safeRun(),
which polls pendingAddEntries,
gets the callback on OpAddEntry (which is the PersistentTopic instance)
and calls [PersistentTopic].addComplete(lastEntry, data.asReadOnly(), ctx),
which calls publishContext.completed(..) on Producer.MessagePublishContext,
which calls Producer.ServerCnx.execute(this) on the MessagePublishContext,
which calls MessagePublishContext.run(),
which triggers Producer.ServerCnx.getCommandSender().sendSendReceiptResponse(..) [SEND_RECEIPT],
which writes a newSendReceiptCommand to the channel.
From there, the client gets the SEND_RECEIPT command from PulsarDecoder,
which calls [ClientCnx].handleSendReceipt(..),
which calls [ProducerImpl].ackReceived(..),
which calls releaseSemaphoreForSendOp(..) to release the semaphore.
The semaphore doesn't block until maxPendingMessages is reached, which is 1000 by default.
After a rollover, pendingAddEntries is also polled. (Could this access race with the other path that's polling pendingAddEntries?) Here's how this happens:
Something triggers [ManagedLedgerImpl].createComplete(..),
which calls [ManagedLedgerImpl].updateLedgersListAfterRollover(MetaStoreCallback<Void>),
which calls [MetaStoreImpl].asyncUpdateLedgerIds(..),
which calls callback.operationComplete(..) on the MetaStoreCallback<Void>,
which calls [ManagedLedgerImpl].updateLedgersIdsComplete(..),
which polls for pendingAddEntries
which calls op.initiate() on each OpAddEntry in pendingAddEntries,
which calls ledger.asyncAddEntry(..),
which calls [LedgerHandle].asyncAddEntry(..),
which calls [LedgerHandle].doAsyncAddEntry(op),
which adds the op to pendingAddOps on the LedgerHandle instance,
which calls [PendingAddOp].cb.addCompleteWithLatency(..)
which calls the callback on [PendingAddOp], which is [OpAddEntry]
which calls addCompleteWithLatency on the AddCallback interface,
which calls [OpAddEntry].addComplete(..)
which, if it succeeded:
changes its state and recycles it if completed or if there was a failure, it triggers [OpAddEntry].safeRun()
which removes itself from [ManagedLedgerImpl].pendingAddEntries
and triggers cb.addComplete(..) on [PersistentTopic],
which triggers publishContext.completed(..) on [Producer.MessagePublishContext]
which triggers producer.publishOperationCompleted()
which decrements pendingPublishAcks
It's still not clear where the ack's are getting lost, so there must be another part of the flow that I'm missing.
After spending many hours digging through the ack paths and not finding any issues, I took another look at the client (ProducerImpl), and I noticed something interesting in the heap dump. ProducerImpl is in a Connecting state, so it's waiting to get the connection.
However, [ProducerImpl].connectedSince says it's been connected for about 3 days...
If it's in a Connecting state, that implies it was disconnected at some point.
If there's a connectivity issue, that would explain why this bug has been so hard to reproduce and why it can't be reproduced locally. It could be that some network hardware is doing something weird with the connection, and the client doesn't handle it correctly and gets stuck in a Connecting state and doesn't try re-establishing the connection. So, it's just waiting forever for the connection to establish.
When in the Connecting state, in ProducerImpl.sendAsync(..) , ProducerImpl.isValidProducerState(..) returns true even though we haven't completed the establishment of the connection. When that method returns true, it allows the producer to enqueue messages.
Sure enough, [ProducerImpl].connectionHandler.state.pendingMessages contains all (exactly) 1000 of the OpSendMsg that are blocking the semaphore. (The semaphore blocks once 1000 messages accumulate that haven't been ack'd.)
It also has exactly 1000 null value entries for pendingCallbacks, but I'm not sure if that means anything.
In the function logs, I'm noticing a lot of messages like this:
00:30:00.452 [pulsar-timer-5-1] INFO org.apache.pulsar.client.impl.ConnectionHandler - [persistent://myTenant/processing/random-1-out] [green-test-126-142] Reconnecting after connection was closed
00:30:00.453 [pulsar-client-io-1-2] INFO org.apache.pulsar.client.impl.ProducerImpl - [persistent://myTenant/processing/random-1-out] [green-test-126-142] Creating producer on cnx [id: 0xd7dc2240, L:/10.20.55.42:45836 - R:server10.example.com.com/10.20.55.42:6650]
00:30:59.028 [pulsar-timer-5-1] INFO org.apache.pulsar.client.impl.ConnectionHandler - [persistent://myTenant/processing/random-1-out] [green-test-126-142] Reconnecting after connection was closed
00:30:59.029 [pulsar-client-io-1-2] INFO org.apache.pulsar.client.impl.ProducerImpl - [persistent://myTenant/processing/random-1-out] [green-test-126-142] Creating producer on cnx [id: 0xd7dc2240, L:/10.20.55.42:45836 - R:server10.example.com.com/10.20.55.42:6650]
It looks like the function keeps trying to reconnect, but the connection is immediately (within 1 millisecond) closed. So, the function is never able to re-establish a healthy connection. If it can't establish a healthy connection, it can't produce the messages or receive ack's from the broker. So, this is a viable root cause.
Activity
cdbartholomew commentedon Jan 14, 2020
FWIW, @devinbost I am suspicious of the netty version in the 2.4.X stream. There is a know memory usage issue (netty/netty#8814) in the 4.1.32 version of netty that is used in the stream. When I was testing, I would see issues like you are describing. Then I patched in the latest version of netty, and things seemed better. I have been running with a patched 2.4.2 for a while and have not seen any issues. You may be experiencing something completely different, but it might be worth trying 2.4.2 + latest netty.
sijie commentedon Jan 15, 2020
@devinbost have you looked into
permitswhen this issue happens?devinbost commentedon Jan 21, 2020
@sijie We have, but I can't remember exactly what our findings were.
Is there anything in particular that we should look for regarding
permits?devinbost commentedon Jan 21, 2020
@cdbartholomew We actually started experiencing this issue before 2.4.0.
devinbost commentedon Jan 21, 2020
I noticed that each topic lives on a single broker, which creates a single point of failure.
Is there any interest in making topics higher availability? (I suppose it would be a workaround, but it might help prevent other issues.)
sijie commentedon Jan 21, 2020
We (StreamNative) have been helping folks from Tencent at developing a feature called ReadOnly brokers. It allows a topic can have multiple owners (one writeable owner and multiple readonly owners). It has been running on production for a while. They will contribute it back soon.
sijie commentedon Jan 21, 2020
Incorrect permits has been one of the main reasons causing the consumer to be stalled. You can use "unload" command to unload a topic or a namespace bundle to trigger a consumer reconnect. It resets the consumer state to mitigate the problem.
@codelipenghui and @jiazhai are working a proposal on improving the permits protocol.
I am not sure if your problem is related to permits. but if the same problem occurs, the first thing you should do is to use
topic statsortopic stats-internalto get the stats or internal stats of a topic.devinbost commentedon Jan 21, 2020
I found an example involving a dead topic. (This was on a low-volume topic.)

devinbost commentedon Jan 21, 2020
Here's another case where we saw the topics on a particular broker freeze.

Notice that both topics on broker 09 froze.
sijie commentedon Jan 22, 2020
Interestingly, the available permits seems to be fine (1000). Are you able to get some more stats that we can help debug?
devinbost commentedon Jan 25, 2020
We will need to capture some stats when this happens next. After my team made some changes to improve the stability of the Zookeeper cluster, the frequency of this issue decreased on v2.4.0. So, we will need to update one of the clusters to use 2.4.2 to reproduce this issue again.
devinbost commentedon Jan 25, 2020
I also noticed that some of the bookkeeper nodes are currently running:
apachepulsar/pulsar-all:2.3.0and some of them are running:
streamlio/pulsar-all:2.4.0-streamlio-24I don't know if that would have anything to do with the issue.
sijie commentedon Jan 25, 2020
usually, this kind of problem is not related to bookkeeper. Is the broker running the same version and what is the version?
86 remaining items
devinbost commentedon May 26, 2021
Many thanks to @lhotari for figuring out how to reproduce this bug outside of my environment.
lhotari commentedon May 28, 2021
I have reported a separate issue about a direct memory leak, it's #10738 . It includes a full repro case with a helm deployment that can be used to reproduce the issue in minikube (requires sufficient RAM) (or any k8s environment).
JohnMops commentedon Jun 20, 2021
Any news regarding this one?
We are seeing a topic stops every 9 seconds and needs to be reloaded.
eolivelli commentedon Jun 20, 2021
@JohnMops did you update to Pulsar 2.8.0?
devinbost commentedon Jun 20, 2021
devinbost commentedon Jun 29, 2021
Related to #10813 except that issue seems to not occur if batching is disabled.
As an update, I've reproduced this bug even after correcting the non-standard broker.conf settings that were mentioned earlier in this issue.
devinbost commentedon Jul 3, 2021
I mapped out more of the ack flow, so I will add it to what I documented here and make it more readable.
The bracket notation below is intended to specify an instance of the class (to distinguish from a static method call.)
When
ProducerImplsends the messages, it buildsnewSendcommand instances,which get picked up by
ServerCnx.handleSend(..),which goes to
Producer.publishMessage(..),then
PersistentTopic.publishMessage(..)which calls
asyncAddEntry(headersAndPayload, publishContext),which calls
[PersistentTopic].ledger.asyncAddEntry(headersAndPayload, (int) publishContext.getNumberOfMessages(), this, publishContext)which creates the
OpAddEntryand callsinternalAsyncAddEntry(addOperation)on a different thread,which adds
OpAddEntryto[ManagedLedgerImpl].pendingAddEntriesFrom somewhere (it's not clear to me exactly where yet) we call
OpAddEntry.safeRun(),which polls
pendingAddEntries,gets the callback on
OpAddEntry(which is thePersistentTopicinstance)and calls
[PersistentTopic].addComplete(lastEntry, data.asReadOnly(), ctx),which calls
publishContext.completed(..)onProducer.MessagePublishContext,which calls
Producer.ServerCnx.execute(this)on theMessagePublishContext,which calls
MessagePublishContext.run(),which triggers
Producer.ServerCnx.getCommandSender().sendSendReceiptResponse(..)[SEND_RECEIPT],which writes a
newSendReceiptCommandto the channel.From there, the client gets the
SEND_RECEIPTcommand fromPulsarDecoder,which calls
[ClientCnx].handleSendReceipt(..),which calls
[ProducerImpl].ackReceived(..),which calls
releaseSemaphoreForSendOp(..)to release the semaphore.The semaphore doesn't block until
maxPendingMessagesis reached, which is 1000 by default.After a rollover,
pendingAddEntriesis also polled. (Could this access race with the other path that's pollingpendingAddEntries?) Here's how this happens:Something triggers
[ManagedLedgerImpl].createComplete(..),which calls
[ManagedLedgerImpl].updateLedgersListAfterRollover(MetaStoreCallback<Void>),which calls
[MetaStoreImpl].asyncUpdateLedgerIds(..),which calls
callback.operationComplete(..)on theMetaStoreCallback<Void>,which calls
[ManagedLedgerImpl].updateLedgersIdsComplete(..),which polls for
pendingAddEntrieswhich calls
op.initiate()on eachOpAddEntryinpendingAddEntries,which calls
ledger.asyncAddEntry(..),which calls
[LedgerHandle].asyncAddEntry(..),which calls
[LedgerHandle].doAsyncAddEntry(op),which adds the
optopendingAddOpson theLedgerHandleinstance,which calls
[PendingAddOp].cb.addCompleteWithLatency(..)which calls the callback on
[PendingAddOp], which is[OpAddEntry]which calls
addCompleteWithLatencyon theAddCallbackinterface,which calls
[OpAddEntry].addComplete(..)which, if it succeeded:
changes its state and recycles it if completed or if there was a failure, it triggers
[OpAddEntry].safeRun()which removes itself from
[ManagedLedgerImpl].pendingAddEntriesand triggers
cb.addComplete(..)on[PersistentTopic],which triggers
publishContext.completed(..)on[Producer.MessagePublishContext]which triggers
producer.publishOperationCompleted()which decrements
pendingPublishAcksIt's still not clear where the ack's are getting lost, so there must be another part of the flow that I'm missing.
devinbost commentedon Jul 6, 2021
After spending many hours digging through the ack paths and not finding any issues, I took another look at the client (
ProducerImpl), and I noticed something interesting in the heap dump.ProducerImplis in aConnectingstate, so it's waiting to get the connection.However,
[ProducerImpl].connectedSincesays it's been connected for about 3 days...If it's in a
Connectingstate, that implies it was disconnected at some point.If there's a connectivity issue, that would explain why this bug has been so hard to reproduce and why it can't be reproduced locally. It could be that some network hardware is doing something weird with the connection, and the client doesn't handle it correctly and gets stuck in a
Connectingstate and doesn't try re-establishing the connection. So, it's just waiting forever for the connection to establish.When in the
Connectingstate, inProducerImpl.sendAsync(..),ProducerImpl.isValidProducerState(..)returns true even though we haven't completed the establishment of the connection. When that method returns true, it allows the producer to enqueue messages.Sure enough,
[ProducerImpl].connectionHandler.state.pendingMessagescontains all (exactly) 1000 of the OpSendMsg that are blocking the semaphore. (The semaphore blocks once 1000 messages accumulate that haven't been ack'd.)It also has exactly 1000 null value entries for
pendingCallbacks, but I'm not sure if that means anything.In the function logs, I'm noticing a lot of messages like this:
It looks like the function keeps trying to reconnect, but the connection is immediately (within 1 millisecond) closed. So, the function is never able to re-establish a healthy connection. If it can't establish a healthy connection, it can't produce the messages or receive ack's from the broker. So, this is a viable root cause.
devinbost commentedon Dec 17, 2021
This bug has been resolved in DataStax Luna Streaming 2.7.2_1.1.21
skyrocknroll commentedon Dec 17, 2021
@devinbost Which version of apache pulsar has this fix ?
marcioapm commentedon Jan 12, 2022
Hi @devinbost is this is 2.9.1?
lhotari commentedon Jan 13, 2022
@skyrocknroll @marcioapm All required fixes are included in Apache Pulsar 2.7.4 and 2.8.2 versions.
lhotari commentedon Apr 12, 2022
#15031 and #15067 resolve an issue with a similar symptom, where subscriptions freeze.
JohnMops commentedon Sep 24, 2022
Still have stalled topic issue in 2.9.2