Skip to content

Commit

Permalink
Fixes #8558 - Idle timeout occurs on HTTP/2 with InputStreamResponseL…
Browse files Browse the repository at this point in the history
…istener.

Updates after review.

Signed-off-by: Simone Bordet <simone.bordet@gmail.com>
  • Loading branch information
sbordet committed Sep 15, 2022
1 parent 0b06968 commit c5c5588
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;

public class HttpClientTransportOverHTTP2Test extends AbstractTest
{
Expand Down Expand Up @@ -634,13 +633,10 @@ public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
});

var requestCount = 10_000;
var progress = new AtomicInteger(0);
IntStream.range(0, requestCount).forEach(i ->
{
try
{
if (progress.incrementAndGet() % 1000 == 0)
System.err.printf("progress %d/%d%n", progress.get(), requestCount);
InputStreamResponseListener listener = new InputStreamResponseListener();
client.newRequest("localhost", connector.getLocalPort()).headers(httpFields -> httpFields.put("X-Request-Id", Integer.toString(i))).send(listener);
Response response = listener.get(15, TimeUnit.SECONDS);
Expand All @@ -649,7 +645,7 @@ public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
}
catch (Exception e)
{
fail(e);
throw new RuntimeException(e);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
public class HttpReceiverOverHTTP3 extends HttpReceiver implements Stream.Client.Listener
{
private static final Logger LOG = LoggerFactory.getLogger(HttpReceiverOverHTTP3.class);
private boolean notifySuccess;
private volatile boolean notifySuccess;

protected HttpReceiverOverHTTP3(HttpChannelOverHTTP3 channel)
{
Expand Down Expand Up @@ -86,6 +86,7 @@ public void onResponse(Stream.Client stream, HeadersFrame frame)

// TODO: add support for HttpMethod.CONNECT.

notifySuccess = frame.isLast();
if (responseHeaders(exchange))
{
int status = response.getStatus();
Expand All @@ -98,7 +99,6 @@ public void onResponse(Stream.Client stream, HeadersFrame frame)
{
if (LOG.isDebugEnabled())
LOG.debug("stalling response processing, no demand after headers on {}", this);
notifySuccess = frame.isLast();
}
}
}
Expand All @@ -118,12 +118,16 @@ public void onDataAvailable(Stream.Client stream)
ByteBuffer byteBuffer = data.getByteBuffer();
if (byteBuffer.hasRemaining())
{
if (data.isLast())
notifySuccess = true;

Callback callback = Callback.from(Invocable.InvocationType.NON_BLOCKING, data::complete, x ->
{
data.complete();
if (responseFailure(x))
stream.reset(HTTP3ErrorCode.REQUEST_CANCELLED_ERROR.code(), x);
});

boolean proceed = responseContent(exchange, byteBuffer, callback);
if (proceed)
{
Expand All @@ -136,7 +140,6 @@ public void onDataAvailable(Stream.Client stream)
{
if (LOG.isDebugEnabled())
LOG.debug("stalling response processing, no demand after {} on {}", data, this);
notifySuccess = data.isLast();
}
}
else
Expand Down

0 comments on commit c5c5588

Please sign in to comment.