Skip to content
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

fix: Propagate outgoing stream errors to incoming pipeline #311

Open
wants to merge 1 commit into
base: 00306-block-node-helidon
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,12 @@ protected void send(
* receives bytes from the handlers to send to the client.
*/
private final class SendToClientSubscriber implements Flow.Subscriber<Bytes> {
/**
* Keep track of whether the onError method has been called. This is necessary because the
* onError method can be called multiple times, and we only want to handle it once.
*/
private boolean onErrorCalled = false;

@Override
public void onSubscribe(@NonNull final Flow.Subscription subscription) {
// FUTURE: Add support for flow control
Expand Down Expand Up @@ -709,6 +715,13 @@ public void onNext(@NonNull final Bytes response) {

@Override
public void onError(@NonNull final Throwable throwable) {
// don't perform error handling multiple times
// this is necessary, so that the incoming and outgoing streams don't circularly close each other
if (onErrorCalled) {
return;
}
onErrorCalled = true;

if (throwable instanceof final GrpcException grpcException) {
new TrailerBuilder()
.grpcStatus(grpcException.status())
Expand All @@ -718,6 +731,8 @@ public void onError(@NonNull final Throwable throwable) {
LOGGER.log(ERROR, "Failed to send response", throwable);
new TrailerBuilder().grpcStatus(GrpcStatus.INTERNAL).send();
}

pipeline.onError(throwable);
error();
}

Expand Down
Loading