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

Jetty Reactive client hangs for HTTP 401 responses #12652

Open
bclozel opened this issue Dec 18, 2024 · 1 comment · May be fixed by #12654
Open

Jetty Reactive client hangs for HTTP 401 responses #12652

bclozel opened this issue Dec 18, 2024 · 1 comment · May be fixed by #12654
Assignees
Labels
Bug For general bugs on Jetty side

Comments

@bclozel
Copy link

bclozel commented Dec 18, 2024

Jetty version(s)
org.eclipse.jetty:jetty-reactive-httpclient:4.0.8

Jetty Environment
core

Java version/vendor (use: java -version)
openjdk version "17.0.13" 2024-10-15 LTS

OS type/version
macOS Sequoia 15.2 (24C101)

Description
When receiving an HTTP 401 response, the Jetty HTTP reactive client hangs and never publishes the response.

How to reproduce?

HttpClient httpClient = new HttpClient();
httpClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME);
httpClient.start();
Request request = httpClient.newRequest("https://httpbin.org/status/401");
ReactiveRequest reactiveRequest = ReactiveRequest.newBuilder(request).abortOnCancel(true).build();
Mono<ReactiveResponse> responseMono = Mono.fromDirect(reactiveRequest.response());
ReactiveResponse reactiveResponse = responseMono.block(Duration.ofSeconds(3));
System.out.println(reactiveResponse.getHeaders().toString());
System.out.println(reactiveResponse.getStatus());

The subscriber times out waiting:

java.lang.IllegalStateException: Timeout on blocking read for 3000000000 NANOSECONDS
	at reactor.core.publisher.BlockingSingleSubscriber.blockingGet(BlockingSingleSubscriber.java:129) ~[reactor-core-3.6.12.jar:3.6.12]
	at reactor.core.publisher.Mono.block(Mono.java:1807) ~[reactor-core-3.6.12.jar:3.6.12]

Am I misusing the reactive API in this case? Note that changing the URL to "https://httpbin.org/status/404" works as expected.

@sbordet
Copy link
Contributor

sbordet commented Dec 18, 2024

@bclozel you need to swap these 2 lines:

httpClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME);
httpClient.start();

to be:

httpClient.start();
httpClient.getProtocolHandlers().remove(WWWAuthenticationProtocolHandler.NAME);

I agree that your code is more intuitive, but for historical reasons we add the ProtocolHandlers in doStart().

Having said that, we do have a bug, as your test should have worked (with WWWAuthenticationProtocolHandler present).

The issue is that ResponseListeners.emitEvents() does not notify onContentSource() for zero-length content.
In case of the reactive HttpClient the missing notification does not invoke ResponseListenerProcessor.onContentSource() which is vital to set up the publisher/subscriber chain.

@sbordet sbordet self-assigned this Dec 18, 2024
sbordet added a commit that referenced this issue Dec 18, 2024
Fixed ResponseListeners.emitEvents() to emit the "contentSource" event in all cases.

Signed-off-by: Simone Bordet <[email protected]>
@sbordet sbordet moved this to 🏗 In progress in Jetty 12.0.17 Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
Status: 🏗 In progress
Development

Successfully merging a pull request may close this issue.

2 participants