From 9e196b3631af0156ce9958a2f631894968211a4c Mon Sep 17 00:00:00 2001 From: Daniel Fuchs Date: Tue, 23 May 2023 12:07:23 +0000 Subject: [PATCH] 8308565: HttpClient: Sanitize logging while stopping Reviewed-by: jpai --- .../internal/net/http/Http2ClientImpl.java | 7 +++-- .../internal/net/http/Http2Connection.java | 29 ++++++++++++++++--- 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java b/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java index 160ded9ae6f..7b196536736 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2ClientImpl.java @@ -57,8 +57,7 @@ class Http2ClientImpl { private final HttpClientImpl client; - // only accessed from within synchronized blocks - private boolean stopping; + private volatile boolean stopping; Http2ClientImpl(HttpClientImpl client) { this.client = client; @@ -293,4 +292,8 @@ class Http2ClientImpl { 16 * K, 16 * K * K -1, 16 * K)); return frame; } + + public boolean stopping() { + return stopping; + } } diff --git a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java index a55189a7892..7821f2a1e42 100644 --- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java +++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java @@ -1363,6 +1363,19 @@ class Http2Connection { Stream stream = oh.getAttachment(); assert stream.streamid == 0; int streamid = nextstreamid; + Throwable cause = null; + synchronized (this) { + if (isMarked(closedState, SHUTDOWN_REQUESTED)) { + cause = this.cause; + if (cause == null) { + cause = new IOException("Connection closed"); + } + } + } + if (cause != null) { + stream.cancelImpl(cause); + return null; + } if (stream.registerStream(streamid, false)) { // set outgoing window here. This allows thread sending // body to proceed. @@ -1399,8 +1412,12 @@ class Http2Connection { publisher.signalEnqueued(); } catch (IOException e) { if (!isMarked(closedState, SHUTDOWN_REQUESTED)) { - Log.logError(e); - shutdown(e); + if (!client2.stopping()) { + Log.logError(e); + shutdown(e); + } else if (debug.on()) { + debug.log("Failed to send %s while stopping: %s", frame, e); + } } } } @@ -1417,8 +1434,12 @@ class Http2Connection { publisher.signalEnqueued(); } catch (IOException e) { if (!isMarked(closedState, SHUTDOWN_REQUESTED)) { - Log.logError(e); - shutdown(e); + if (!client2.stopping()) { + Log.logError(e); + shutdown(e); + } else if (debug.on()) { + debug.log("Failed to send %s while stopping: %s", frame, e); + } } } }