Skip to content

Commit

Permalink
Bug fix: corrected error handling in AbstractAsyncPushHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
ok2c committed Oct 10, 2024
1 parent 6da87d3 commit d43f13a
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.apache.hc.core5.concurrent.FutureCallback;
import org.apache.hc.core5.http.EntityDetails;
Expand All @@ -52,9 +53,11 @@
public abstract class AbstractAsyncPushHandler<T> implements AsyncPushConsumer {

private final AsyncResponseConsumer<T> responseConsumer;
private final AtomicReference<HttpRequest> promiseRef;

public AbstractAsyncPushHandler(final AsyncResponseConsumer<T> responseConsumer) {
this.responseConsumer = Args.notNull(responseConsumer, "Response consumer");
this.promiseRef = new AtomicReference<>();
}

/**
Expand Down Expand Up @@ -83,6 +86,7 @@ public final void consumePromise(
final HttpResponse response,
final EntityDetails entityDetails,
final HttpContext httpContext) throws HttpException, IOException {
promiseRef.compareAndSet(null, promise);
responseConsumer.consumeResponse(response, entityDetails, httpContext, new FutureCallback<T>() {

@Override
Expand All @@ -96,7 +100,6 @@ public void completed(final T result) {

@Override
public void failed(final Exception cause) {
handleError(promise, cause);
releaseResources();
}

Expand Down Expand Up @@ -126,6 +129,7 @@ public final void streamEnd(final List<? extends Header> trailers) throws HttpEx
@Override
public final void failed(final Exception cause) {
responseConsumer.failed(cause);
handleError(promiseRef.get(), cause);
releaseResources();
}

Expand Down

0 comments on commit d43f13a

Please sign in to comment.