mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-22 03:54:33 +02:00
8216974: HttpConnection not returned to the pool after 204 response
MultiExchange now call nullBody() on Exchange after receiving 204 Reviewed-by: chegar
This commit is contained in:
parent
617f75c8cf
commit
ca77adf19f
7 changed files with 66 additions and 10 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -151,6 +151,13 @@ final class Exchange<T> {
|
|||
}
|
||||
}
|
||||
|
||||
// Called for 204 response - when no body is permitted
|
||||
// This is actually only needed for HTTP/1.1 in order
|
||||
// to return the connection to the pool (or close it)
|
||||
void nullBody(HttpResponse<T> resp, Throwable t) {
|
||||
exchImpl.nullBody(resp, t);
|
||||
}
|
||||
|
||||
public CompletableFuture<T> readBodyAsync(HttpResponse.BodyHandler<T> handler) {
|
||||
// If we received a 407 while establishing the exchange
|
||||
// there will be no body to read: bodyIgnored will be true,
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -161,6 +161,12 @@ abstract class ExchangeImpl<T> {
|
|||
}
|
||||
}
|
||||
|
||||
// Called for 204 response - when no body is permitted
|
||||
void nullBody(HttpResponse<T> resp, Throwable t) {
|
||||
// only needed for HTTP/1.1 to close the connection
|
||||
// or return it to the pool
|
||||
}
|
||||
|
||||
/* The following methods have separate HTTP/1.1 and HTTP/2 implementations */
|
||||
|
||||
abstract CompletableFuture<ExchangeImpl<T>> sendHeadersAsync();
|
||||
|
@ -177,6 +183,7 @@ abstract class ExchangeImpl<T> {
|
|||
*/
|
||||
abstract CompletableFuture<Void> ignoreBody();
|
||||
|
||||
|
||||
/** Gets the response headers. Completes before body is read. */
|
||||
abstract CompletableFuture<Response> getResponseAsync(Executor executor);
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -28,6 +28,7 @@ package jdk.internal.net.http;
|
|||
import java.io.IOException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.http.HttpClient;
|
||||
import java.net.http.HttpResponse;
|
||||
import java.net.http.HttpResponse.BodyHandler;
|
||||
import java.net.http.HttpResponse.BodySubscriber;
|
||||
import java.nio.ByteBuffer;
|
||||
|
@ -382,6 +383,13 @@ class Http1Exchange<T> extends ExchangeImpl<T> {
|
|||
return response.ignoreBody(executor);
|
||||
}
|
||||
|
||||
// Used for those response codes that have no body associated
|
||||
@Override
|
||||
public void nullBody(HttpResponse<T> resp, Throwable t) {
|
||||
response.nullBody(resp, t);
|
||||
}
|
||||
|
||||
|
||||
ByteBuffer drainLeftOverBytes() {
|
||||
synchronized (lock) {
|
||||
asyncReceiver.stop();
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -267,6 +267,15 @@ class Http1Response<T> {
|
|||
}
|
||||
}
|
||||
|
||||
// Used for those response codes that have no body associated
|
||||
public void nullBody(HttpResponse<T> resp, Throwable t) {
|
||||
if (t != null) connection.close();
|
||||
else {
|
||||
return2Cache = !request.isWebSocket();
|
||||
onFinished();
|
||||
}
|
||||
}
|
||||
|
||||
static final Flow.Subscription NOP = new Flow.Subscription() {
|
||||
@Override
|
||||
public void request(long n) { }
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -85,8 +85,8 @@ abstract class HttpConnection implements Closeable {
|
|||
new IdentityHashMap<>();
|
||||
void add(CompletionStage<?> cf) {
|
||||
synchronized(operations) {
|
||||
cf.whenComplete((r,t)-> remove(cf));
|
||||
operations.put(cf, Boolean.TRUE);
|
||||
cf.whenComplete((r,t)-> remove(cf));
|
||||
}
|
||||
}
|
||||
boolean remove(CompletionStage<?> cf) {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2019, Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
|
@ -242,7 +242,8 @@ class MultiExchange<T> {
|
|||
result.complete(this.response);
|
||||
}
|
||||
});
|
||||
return result;
|
||||
// ensure that the connection is closed or returned to the pool.
|
||||
return result.whenComplete(exch::nullBody);
|
||||
}
|
||||
|
||||
private CompletableFuture<HttpResponse<T>>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue