Skip to content

Commit

Permalink
handle review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ludovic Orban <[email protected]>
  • Loading branch information
lorban committed Dec 10, 2024
1 parent fe418fd commit 1a8c6f2
Showing 1 changed file with 18 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1314,29 +1314,22 @@ public void succeeded()
LOG.debug("write succeeded {}", this);
Callback callback;
HttpChannelState httpChannel;
Throwable noChannelFailure = null;
try (AutoLock ignored = _request._lock.lock())
{
callback = _writeCallback;
_writeCallback = null;
httpChannel = _request.lockedGetHttpChannelState();
httpChannel.lockedStreamSendCompleted(true);
}
catch (Throwable failure)
{
callback = null;
httpChannel = null;
noChannelFailure = failure;
httpChannel = _request._httpChannelState;
if (httpChannel != null)
httpChannel.lockedStreamSendCompleted(true);
}

if (httpChannel != null && callback != null)
{
httpChannel._writeInvoker.run(callback::succeeded);
}
else
if (callback != null)
{
// Channel already completed, just fail the callback.
HttpChannelState.failed(callback, noChannelFailure);
if (httpChannel != null)
httpChannel._writeInvoker.run(callback::succeeded);
else
// Channel already completed, just fail the callback.
HttpChannelState.failed(callback, new IllegalStateException("channel already completed"));
}
}

Expand All @@ -1357,31 +1350,23 @@ public void failed(Throwable x)
LOG.debug("write failed {}", this, x);
Callback callback;
HttpChannelState httpChannel;
Throwable noChannelFailure = null;
try (AutoLock ignored = _request._lock.lock())
{
_writeFailure = x;
callback = _writeCallback;
_writeCallback = null;
httpChannel = _request.lockedGetHttpChannelState();
httpChannel.lockedStreamSendCompleted(false);
}
catch (Throwable failure)
{
callback = null;
httpChannel = null;
noChannelFailure = failure;
httpChannel = _request._httpChannelState;
if (httpChannel != null)
httpChannel.lockedStreamSendCompleted(false);
}

if (httpChannel != null && callback != null)
{
Callback finalCallback = callback;
httpChannel._writeInvoker.run(() -> HttpChannelState.failed(finalCallback, x));
}
else
if (callback != null)
{
// Channel already completed, just fail the callback.
HttpChannelState.failed(callback, noChannelFailure);
if (httpChannel != null)
httpChannel._writeInvoker.run(() -> HttpChannelState.failed(callback, x));
else
// Channel already completed, just fail the callback.
HttpChannelState.failed(callback, ExceptionUtil.combine(x, new IllegalStateException("channel already completed")));
}
}

Expand Down

0 comments on commit 1a8c6f2

Please sign in to comment.