Skip to content

moves error propagation out of the synchronise to avoid deadlock #1060

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

Merged
merged 1 commit into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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