Skip to content

Commit

Permalink
minimal fix
Browse files Browse the repository at this point in the history
  • Loading branch information
jrhee17 committed Dec 12, 2024
1 parent d3303e2 commit 83d14bb
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,16 @@ void close(@Nullable Throwable cause, boolean cancel) {
requestAutoAbortDelayMillis, TimeUnit.MILLISECONDS);
}

private void closeAction(@Nullable Throwable cause) {
private boolean closeAction(@Nullable Throwable cause) {
final boolean closed;
if (cause != null) {
delegate.close(cause);
closed = delegate.tryClose(cause);
ctx.logBuilder().endResponse(cause);
} else {
delegate.close();
closed = delegate.tryClose();
ctx.logBuilder().endResponse();
}
return closed;
}

private void cancelAction(@Nullable Throwable cause) {
Expand All @@ -262,8 +264,10 @@ private void cancelTimeoutAndLog(@Nullable Throwable cause, boolean cancel) {
cancelAction(cause);
return;
}
if (delegate.isOpen()) {
closeAction(cause);

// don't log if the cause will be exposed via the response/log
if (delegate.isOpen() && closeAction(cause)) {
return;
}

// the context has been cancelled either by timeout or by user invocation
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,28 +441,41 @@ private void handleCloseEvent(SubscriptionImpl subscription, CloseEvent o) {

@Override
public void close() {
if (setState(State.OPEN, State.CLOSED)) {
addObjectOrEvent(SUCCESSFUL_CLOSE);
}
tryClose();
}

@Override
public final void close(Throwable cause) {
requireNonNull(cause, "cause");
if (cause instanceof CancelledSubscriptionException) {
throw new IllegalArgumentException("cause: " + cause + " (must use Subscription.cancel())");
}

tryClose(cause);
}

/**
* Tries to close the stream.
*
* @return {@code true} if the stream has been closed by this method call.
* {@code false} if the stream has been closed already by another party.
*/
@UnstableApi
public final boolean tryClose() {
if (setState(State.OPEN, State.CLOSED)) {
addObjectOrEvent(SUCCESSFUL_CLOSE);
return true;
}
return false;
}

/**
* Tries to close the stream with the specified {@code cause}.
*
* @return {@code true} if the stream has been closed by this method call.
* {@code false} if the stream has been closed already by other party.
* {@code false} if the stream has been closed already by another party.
*/
public final boolean tryClose(Throwable cause) {
if (cause instanceof CancelledSubscriptionException) {
throw new IllegalArgumentException("cause: " + cause + " (must use Subscription.cancel())");
}
if (setState(State.OPEN, State.CLOSED)) {
addObjectOrEvent(new CloseEvent(cause));
return true;
Expand Down

0 comments on commit 83d14bb

Please sign in to comment.