Skip to content

Commit

Permalink
fix: synchronize known pubsub nodes to avoid CME (Fixes #134) (#135)
Browse files Browse the repository at this point in the history
  • Loading branch information
skyrising authored Dec 12, 2020
1 parent 653a922 commit 83cb743
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions carpetmodSrc/carpet/pubsub/PubSubManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ public final class PubSubManager {
*/
@Nullable
public PubSubNode getNode(String name) {
return knownNodes.get(name);
synchronized (knownNodes) {
return knownNodes.get(name);
}
}

/**
Expand All @@ -35,14 +37,16 @@ public PubSubNode getNode(String name) {
* @see PubSubNode#getOrCreateChildNode(Collection)
*/
public PubSubNode getOrCreateNode(String name) {
return knownNodes.computeIfAbsent(name, name1 -> {
String[] path = name1.split("\\.");
PubSubNode node = ROOT.getOrCreateChildNode(path);
for (PubSubNode n = node; n != ROOT; n = n.parent) {
knownNodes.put(n.fullName, n);
}
return node;
});
synchronized (knownNodes) {
return knownNodes.computeIfAbsent(name, name1 -> {
String[] path = name1.split("\\.");
PubSubNode node = ROOT.getOrCreateChildNode(path);
for (PubSubNode n = node; n != ROOT; n = n.parent) {
knownNodes.put(n.fullName, n);
}
return node;
});
}
}

public void subscribe(PubSubNode node, PubSubSubscriber subscriber) {
Expand Down

0 comments on commit 83cb743

Please sign in to comment.