Skip to content
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

Fix: deadlock while closing non-persistent topic #1660

Merged
merged 1 commit into from
Apr 27, 2018

Conversation

rdhabalia
Copy link
Contributor

Motivation

Deadlock while closing non-persistent topic.

  • Unload topic iterates over topics map and removing from the map with the same thread can create deadlock.
"pulsar-web-72-23" #251 prio=5 os_prio=0 tid=0x00002aba90001000 nid=0x2428 waiting on condition [0x00002ab907b1a000]
   java.lang.Thread.State: WAITING (parking)
        at sun.misc.Unsafe.park(Native Method)
        - parking to wait for  <0x0000000568e0ba18> (a org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap$Section)
        at java.util.concurrent.locks.StampedLock.acquireWrite(StampedLock.java:1119)
        at java.util.concurrent.locks.StampedLock.writeLock(StampedLock.java:354)
        at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap$Section.remove(ConcurrentOpenHashMap.java:305)
        at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap$Section.access$200(ConcurrentOpenHashMap.java:181)
        at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap.remove(ConcurrentOpenHashMap.java:136)
        at org.apache.pulsar.broker.service.BrokerService.removeTopicFromCache(BrokerService.java:931)
        at org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic.lambda$10(NonPersistentTopic.java:450)
        at org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic$$Lambda$493/445153470.run(Unknown Source)
        at java.util.concurrent.CompletableFuture.uniRun(CompletableFuture.java:705)
        at java.util.concurrent.CompletableFuture.uniRunStage(CompletableFuture.java:717)
        at java.util.concurrent.CompletableFuture.thenRun(CompletableFuture.java:2010)
        at org.apache.pulsar.broker.service.nonpersistent.NonPersistentTopic.close(NonPersistentTopic.java:448)
        at org.apache.pulsar.broker.service.BrokerService$$Lambda$275/707822372.apply(Unknown Source)
        at java.util.concurrent.CompletableFuture.uniComposeStage(CompletableFuture.java:981)
        at java.util.concurrent.CompletableFuture.thenCompose(CompletableFuture.java:2124)
        at org.apache.pulsar.broker.service.BrokerService.lambda$21(BrokerService.java:885)
        at org.apache.pulsar.broker.service.BrokerService$$Lambda$274/1896064809.accept(Unknown Source)
        at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap$Section.forEach(ConcurrentOpenHashMap.java:386)
        at org.apache.pulsar.common.util.collections.ConcurrentOpenHashMap.forEach(ConcurrentOpenHashMap.java:160)
        at org.apache.pulsar.broker.service.BrokerService.unloadServiceUnit(BrokerService.java:880)
        at org.apache.pulsar.broker.namespace.OwnedBundle.handleUnloadRequest(OwnedBundle.java:125)
        at org.apache.pulsar.broker.namespace.NamespaceService.unloadNamespaceBundle(NamespaceService.java:482)
        at org.apache.pulsar.broker.namespace.NamespaceService.unloadNamespaceBundle(NamespaceService.java:478)
        at org.apache.pulsar.broker.admin.Namespaces.unloadNamespaceBundle(Namespaces.java:842)
        at sun.reflect.GeneratedMethodAccessor180.invoke(Unknown Source)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

Modifications

Remove topic from topicCacheMap in a different thread.

Result

It will avoid possible deadlock for non-persistent topic.

@rdhabalia rdhabalia added the type/bug The PR fixed a bug or issue reported a bug label Apr 26, 2018
@rdhabalia rdhabalia added this to the 2.0.0-incubating milestone Apr 26, 2018
@rdhabalia rdhabalia self-assigned this Apr 26, 2018
Copy link
Contributor

@merlimat merlimat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@merlimat merlimat added this to Proposed to backport in Pulsar 1.22.1 patch Release via automation Apr 26, 2018
@sijie
Copy link
Member

sijie commented Apr 27, 2018

retest this please

@merlimat merlimat merged commit 18dc1c8 into apache:master Apr 27, 2018
@rdhabalia rdhabalia deleted the np_dead branch April 28, 2018 22:29
@jai1 jai1 moved this from Proposed to backport to In Progress in Pulsar 1.22.1 patch Release May 2, 2018
@jai1 jai1 moved this from In Progress to Merged for 1.22.1 in Pulsar 1.22.1 patch Release May 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

3 participants