Skip to content

Commit

Permalink
Save iteration to cancel subscriptions
Browse files Browse the repository at this point in the history
Closes gh-914

Signed-off-by: Rossen Stoyanchev <[email protected]>
  • Loading branch information
rstoyanchev committed Oct 6, 2020
1 parent 7af1848 commit 1ca3b99
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,7 @@ class RSocketResponder implements RSocket {
}

private void handleSendProcessorError(Throwable t) {
sendingSubscriptions
.values()
.forEach(
subscription -> {
try {
subscription.cancel();
} catch (Throwable e) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Dropped exception", t);
}
}
});
cleanUpSendingSubscriptions();

channelProcessors
.values()
Expand Down Expand Up @@ -275,7 +264,16 @@ private void cleanup(Throwable e) {
}

private synchronized void cleanUpSendingSubscriptions() {
sendingSubscriptions.values().forEach(Subscription::cancel);
// Iterate explicitly to handle collisions with concurrent removals
for (IntObjectMap.PrimitiveEntry<Subscription> entry : sendingSubscriptions.entries()) {
try {
entry.value().cancel();
} catch (Throwable ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Dropped exception", ex);
}
}
}
sendingSubscriptions.clear();
}

Expand Down

0 comments on commit 1ca3b99

Please sign in to comment.