Skip to content

Catastrophic frequent random subscription freezes, especially on high-traffic topics. #6054

Closed

Description

@devinbost

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
image
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.
image

image

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.

Activity

  1. added
    type/bug
    on Jan 14, 2020
  2. cdbartholomew commented on Jan 14, 2020

    @cdbartholomew
    Contributor

    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.

  3. sijie commented on Jan 15, 2020

    @sijie
    Member

    @devinbost have you looked into permits when this issue happens?

  4. devinbost commented on Jan 21, 2020

    @devinbost
    ContributorAuthor

    @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?

  5. devinbost commented on Jan 21, 2020

    @devinbost
    ContributorAuthor

    @cdbartholomew We actually started experiencing this issue before 2.4.0.

  6. devinbost commented on Jan 21, 2020

    @devinbost
    ContributorAuthor

    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.)

  7. sijie commented on Jan 21, 2020

    @sijie
    Member

    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.

  8. sijie commented on Jan 21, 2020

    @sijie
    Member

    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.

    @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 stats or topic stats-internal to get the stats or internal stats of a topic.

  9. devinbost commented on Jan 21, 2020

    @devinbost
    ContributorAuthor

    I found an example involving a dead topic. (This was on a low-volume topic.)
    image

  10. devinbost commented on Jan 21, 2020

    @devinbost
    ContributorAuthor

    Here's another case where we saw the topics on a particular broker freeze.
    image
    Notice that both topics on broker 09 froze.

  11. sijie commented on Jan 22, 2020

    @sijie
    Member

    Interestingly, the available permits seems to be fine (1000). Are you able to get some more stats that we can help debug?

  12. devinbost commented on Jan 25, 2020

    @devinbost
    ContributorAuthor

    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.

  13. devinbost commented on Jan 25, 2020

    @devinbost
    ContributorAuthor

    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.

  14. sijie commented on Jan 25, 2020

    @sijie
    Member

    usually, this kind of problem is not related to bookkeeper. Is the broker running the same version and what is the version?

  15. 86 remaining items

  16. devinbost commented on May 26, 2021

    @devinbost
    ContributorAuthor

    Many thanks to @lhotari for figuring out how to reproduce this bug outside of my environment.

  17. lhotari commented on May 28, 2021

    @lhotari
    Member

    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).

  18. JohnMops commented on Jun 20, 2021

    @JohnMops

    Any news regarding this one?
    We are seeing a topic stops every 9 seconds and needs to be reloaded.

  19. eolivelli commented on Jun 20, 2021

    @eolivelli
    Contributor

    @JohnMops did you update to Pulsar 2.8.0?

  20. devinbost commented on Jun 20, 2021

    @devinbost
    ContributorAuthor
  21. devinbost commented on Jun 29, 2021

    @devinbost
    ContributorAuthor

    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.

  22. devinbost commented on Jul 3, 2021

    @devinbost
    ContributorAuthor

    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.

  23. devinbost commented on Jul 6, 2021

    @devinbost
    ContributorAuthor

    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.

  24. devinbost commented on Dec 17, 2021

    @devinbost
    ContributorAuthor

    This bug has been resolved in DataStax Luna Streaming 2.7.2_1.1.21

  25. skyrocknroll commented on Dec 17, 2021

    @skyrocknroll
    Contributor

    @devinbost Which version of apache pulsar has this fix ?

  26. marcioapm commented on Jan 12, 2022

    @marcioapm

    This bug has been resolved in DataStax Luna Streaming 2.7.2_1.1.21

    Hi @devinbost is this is 2.9.1?

  27. lhotari commented on Jan 13, 2022

    @lhotari
    Member

    Which version of apache pulsar has this fix ?

    @skyrocknroll @marcioapm All required fixes are included in Apache Pulsar 2.7.4 and 2.8.2 versions.

  28. lhotari commented on Apr 12, 2022

    @lhotari
    Member

    #15031 and #15067 resolve an issue with a similar symptom, where subscriptions freeze.

  29. JohnMops commented on Sep 24, 2022

    @JohnMops

    Still have stalled topic issue in 2.9.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions