8254786: java/net/httpclient/CancelRequestTest.java failing intermittently
Reviewed-by: jpai, michaelm
This commit is contained in:
parent
34d4ffcea5
commit
710653ce18
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, 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
|
||||
@ -144,14 +144,45 @@ final class Exchange<T> {
|
||||
private volatile boolean closeRequested;
|
||||
|
||||
void connection(HttpConnection connection) {
|
||||
this.connection = connection;
|
||||
if (closeRequested) closeConnection();
|
||||
boolean closeRequested;
|
||||
synchronized (this) {
|
||||
// check whether this new connection should be
|
||||
// closed
|
||||
closeRequested = this.closeRequested;
|
||||
if (!closeRequested) {
|
||||
this.connection = connection;
|
||||
} else {
|
||||
// assert this.connection == null
|
||||
this.closeRequested = false;
|
||||
}
|
||||
}
|
||||
if (closeRequested) closeConnection(connection);
|
||||
}
|
||||
|
||||
void closeConnection() {
|
||||
closeRequested = true;
|
||||
HttpConnection connection = this.connection;
|
||||
this.connection = null;
|
||||
HttpConnection connection;
|
||||
synchronized (this) {
|
||||
connection = this.connection;
|
||||
if (connection == null) {
|
||||
closeRequested = true;
|
||||
} else {
|
||||
this.connection = null;
|
||||
}
|
||||
}
|
||||
closeConnection(connection);
|
||||
}
|
||||
|
||||
HttpConnection disable() {
|
||||
HttpConnection connection;
|
||||
synchronized (this) {
|
||||
connection = this.connection;
|
||||
this.connection = null;
|
||||
this.closeRequested = false;
|
||||
}
|
||||
return connection;
|
||||
}
|
||||
|
||||
private static void closeConnection(HttpConnection connection) {
|
||||
if (connection != null) {
|
||||
try {
|
||||
connection.close();
|
||||
@ -160,11 +191,6 @@ final class Exchange<T> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void disable() {
|
||||
connection = null;
|
||||
closeRequested = false;
|
||||
}
|
||||
}
|
||||
|
||||
// Called for 204 response - when no body is permitted
|
||||
@ -524,8 +550,11 @@ final class Exchange<T> {
|
||||
client.client2(),
|
||||
this, e::drainLeftOverBytes)
|
||||
.thenCompose((Http2Connection c) -> {
|
||||
HttpConnection connection = connectionAborter.disable();
|
||||
boolean cached = c.offerConnection();
|
||||
if (cached) connectionAborter.disable();
|
||||
if (!cached && connection != null) {
|
||||
connectionAborter.connection(connection);
|
||||
}
|
||||
Stream<T> s = c.getStream(1);
|
||||
|
||||
if (s == null) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2018, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, 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,7 +28,6 @@ package jdk.internal.net.http;
|
||||
import java.io.EOFException;
|
||||
import java.io.IOException;
|
||||
import java.io.UncheckedIOException;
|
||||
import java.net.ConnectException;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.util.Base64;
|
||||
@ -101,7 +100,7 @@ class Http2ClientImpl {
|
||||
Http2Connection connection = connections.get(key);
|
||||
if (connection != null) {
|
||||
try {
|
||||
if (connection.closed || !connection.reserveStream(true)) {
|
||||
if (!connection.isOpen() || !connection.reserveStream(true)) {
|
||||
if (debug.on())
|
||||
debug.log("removing found closed or closing connection: %s", connection);
|
||||
deleteConnection(connection);
|
||||
@ -153,7 +152,7 @@ class Http2ClientImpl {
|
||||
*/
|
||||
boolean offerConnection(Http2Connection c) {
|
||||
if (debug.on()) debug.log("offering to the connection pool: %s", c);
|
||||
if (c.closed || c.finalStream()) {
|
||||
if (!c.isOpen() || c.finalStream()) {
|
||||
if (debug.on())
|
||||
debug.log("skipping offered closed or closing connection: %s", c);
|
||||
return false;
|
||||
@ -161,6 +160,11 @@ class Http2ClientImpl {
|
||||
|
||||
String key = c.key();
|
||||
synchronized(this) {
|
||||
if (!c.isOpen()) {
|
||||
if (debug.on())
|
||||
debug.log("skipping offered closed or closing connection: %s", c);
|
||||
return false;
|
||||
}
|
||||
Http2Connection c1 = connections.putIfAbsent(key, c);
|
||||
if (c1 != null) {
|
||||
c.setFinalStream();
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2015, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2015, 2022, 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
|
||||
@ -880,6 +880,10 @@ class Http2Connection {
|
||||
}
|
||||
}
|
||||
|
||||
boolean isOpen() {
|
||||
return !closed && connection.channel().isOpen();
|
||||
}
|
||||
|
||||
void resetStream(int streamid, int code) {
|
||||
try {
|
||||
if (connection.channel().isOpen()) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2020, 2021, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2020, 2022, 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
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8245462 8229822
|
||||
* @bug 8245462 8229822 8254786
|
||||
* @summary Tests cancelling the request.
|
||||
* @library /test/lib http2/server
|
||||
* @key randomness
|
||||
|
Loading…
Reference in New Issue
Block a user