Skip to content

Commit

Permalink
moves error propagation out of the synchronise to avoid deadlock (#1060)
Browse files Browse the repository at this point in the history
(cherry picked from commit 6426e45)
  • Loading branch information
OlegDokuka authored and OlegDokuka committed Aug 16, 2022
1 parent ef826de commit 1fe2d64
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
16 changes: 9 additions & 7 deletions rsocket-core/src/main/java/io/rsocket/core/RSocketRequester.java
Original file line number Diff line number Diff line change
Expand Up @@ -345,15 +345,17 @@ private void terminate(Throwable e) {
requesterLeaseTracker.dispose(e);
}

final Collection<FrameHandler> activeStreamsCopy;
synchronized (this) {
final IntObjectMap<FrameHandler> activeStreams = this.activeStreams;
final Collection<FrameHandler> activeStreamsCopy = new ArrayList<>(activeStreams.values());
for (FrameHandler handler : activeStreamsCopy) {
if (handler != null) {
try {
handler.handleError(e);
} catch (Throwable ignored) {
}
activeStreamsCopy = new ArrayList<>(activeStreams.values());
}

for (FrameHandler handler : activeStreamsCopy) {
if (handler != null) {
try {
handler.handleError(e);
} catch (Throwable ignored) {
}
}
}
Expand Down
11 changes: 7 additions & 4 deletions rsocket-core/src/main/java/io/rsocket/core/RSocketResponder.java
Original file line number Diff line number Diff line change
Expand Up @@ -185,15 +185,18 @@ final void doOnDispose() {
requestHandler.dispose();
}

private synchronized void cleanUpSendingSubscriptions() {
final IntObjectMap<FrameHandler> activeStreams = this.activeStreams;
final Collection<FrameHandler> activeStreamsCopy = new ArrayList<>(activeStreams.values());
private void cleanUpSendingSubscriptions() {
final Collection<FrameHandler> activeStreamsCopy;
synchronized (this) {
final IntObjectMap<FrameHandler> activeStreams = this.activeStreams;
activeStreamsCopy = new ArrayList<>(activeStreams.values());
}

for (FrameHandler handler : activeStreamsCopy) {
if (handler != null) {
handler.handleCancel();
}
}
activeStreams.clear();
}

final void handleFrame(ByteBuf frame) {
Expand Down

0 comments on commit 1fe2d64

Please sign in to comment.