Skip to content

IImproved cancellability of HTTP message streams / response timeout support#814

Open
ok2c wants to merge 1 commit intoapache:masterfrom
ok2c:h2stream_timeout_cancellation
Open

IImproved cancellability of HTTP message streams / response timeout support#814
ok2c wants to merge 1 commit intoapache:masterfrom
ok2c:h2stream_timeout_cancellation

Conversation

@ok2c
Copy link
Member

@ok2c ok2c commented Mar 21, 2026

@arturobernalg @rschmitt Please take a look at this change-set and let me know if you see anything wrong or anything disagreeable. The change-set improves in two areas:

  • it makes it possible for the full-featured async HttpClient to abort individual messages exchanges over HTTP/2 connections without shutting down the connection
  • Fixes response time implementation for message exchanges over HTTP/1.1 and HTTP/2 connections

* Improved response timeout support
@ok2c ok2c requested review from arturobernalg and rschmitt March 21, 2026 18:08
Copy link
Contributor

@rschmitt rschmitt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it makes it possible for the full-featured async HttpClient to abort individual messages exchanges over HTTP/2 connections without shutting down the connection

This sounds like it would merit a test case or two:

  1. Cancellation of a message exchange leaves the h2 connection open
  2. Cancellation of one message exchange does not result in the termination of other open message exchanges on the same h2 connection

Fixes response time implementation for message exchanges over HTTP/1.1 and HTTP/2 connections

We should add h2 and maybe h2c coverage to TestAsyncSocketTimeout. I tried it just now, but client.getConnectionManager() returns null, which breaks two out of three test cases. The third test case fails due to the timeout not firing, even with this PR applied, which seems wrong. You can try it by adding this to TestAsyncSocketTimeout:

    @Nested
    class H2 extends AbstractTestSocketTimeout {
        public H2() {
            super(URIScheme.HTTPS, ClientProtocolLevel.H2_ONLY, ServerProtocolLevel.H2_ONLY, false);
        }
    }

final Timeout responseTimeout = requestConfig.getResponseTimeout();
final EndpointInfo endpointInfo = endpoint.getInfo();
final ProtocolVersion version = endpointInfo != null ? endpointInfo.getProtocol() : null;
final boolean supportsStreams = version != null && version.greaterEquals(HttpVersion.HTTP_2);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest supportsMultiplexing or just isH2. "Stream" is an overloaded term and to me mainly connotes InputStreams and the like, i.e. streaming in contrast to buffering.

return new ReleasingAsyncClientExchangeHandler(handler, this::releaseSlot);
}

private Cancellable doExecute(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, preparatory refactorings like this method extraction would be done in separate commits for ease of review (they can still be submitted in a single PR and squashed before merging)

@ok2c
Copy link
Member Author

ok2c commented Mar 21, 2026

@rschmitt Okay. I will split the change-set in a number of smaller ones to make it easier to review. I will also try to put together some integrations tests for message exchange cancellation but request cancellation was notoriously difficult to build reliable tests for. We still have a number of disabled ones that never got fixed because they never fail locally but fail occasionally in CI.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants