http-client-branch: improve error logging for HTTP/2 connection shutdown http-client-branch
authordfuchs
Tue, 12 Jun 2018 17:35:00 +0100
branchhttp-client-branch
changeset 56749 5c86a9790f5a
parent 56748 00b64a0234f5
child 56751 aa677dd4c174
http-client-branch: improve error logging for HTTP/2 connection shutdown
src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java
--- a/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Tue Jun 12 16:07:19 2018 +0100
+++ b/src/java.net.http/share/classes/jdk/internal/net/http/Http2Connection.java	Tue Jun 12 17:35:00 2018 +0100
@@ -661,7 +661,13 @@
             if (closed == true) return;
             closed = true;
         }
-        Log.logError(t);
+        if (Log.errors()) {
+            if (!(t instanceof EOFException) || isActive()) {
+                Log.logError(t);
+            } else if (t != null) {
+                Log.logError("Shutting down connection: {0}", t.getMessage());
+            }
+        }
         Throwable initialCause = this.cause;
         if (initialCause == null) this.cause = t;
         client2.deleteConnection(this);
@@ -1278,8 +1284,11 @@
 
         @Override
         public void onComplete() {
-            if (debug.on()) debug.log("EOF");
-            error = new EOFException("EOF reached while reading");
+            String msg = isActive()
+                    ? "EOF reached while reading"
+                    : "Idle connection closed by HTTP/2 peer";
+            if (debug.on()) debug.log(msg);
+            error = new EOFException(msg);
             completed = true;
             runOrSchedule();
         }
@@ -1293,6 +1302,10 @@
         }
     }
 
+    synchronized boolean isActive() {
+        return numReservedClientStreams > 0 || numReservedServerStreams > 0;
+    }
+
     @Override
     public final String toString() {
         return dbgString();