From 6c94ef5848abb1778a32161e5c085a5b195baf01 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Tue, 6 Oct 2020 17:43:58 +1100 Subject: [PATCH] Issue #5368 - warn if MessageInputStream closed without fully consuming Signed-off-by: Lachlan Roberts --- .../common/message/MessageInputStream.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageInputStream.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageInputStream.java index 369e7ed8625a..985fbe5808f7 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageInputStream.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/message/MessageInputStream.java @@ -87,6 +87,7 @@ public void appendFrame(ByteBuffer framePayload, boolean fin) throws IOException switch (state) { case CLOSED: + LOG.warn("Received content after InputStream closed"); return; case RESUMED: @@ -118,9 +119,11 @@ public void close() if (state == State.CLOSED) return; + if (!buffers.isEmpty() || (activeBuffer != null && activeBuffer.hasRemaining())) + LOG.warn("InputStream closed without fully consuming content"); + state = State.CLOSED; buffers.clear(); - buffers.offer(EOF); } } @@ -156,11 +159,17 @@ public void handlerComplete() SuspendToken resume; synchronized (this) { - state = State.CLOSED; + if (state != State.CLOSED) + { + if (!buffers.isEmpty() || (activeBuffer != null && activeBuffer.hasRemaining())) + LOG.warn("InputStream closed without fully consuming content"); + + state = State.CLOSED; + buffers.clear(); + } + resume = suspendToken; suspendToken = null; - buffers.clear(); - buffers.offer(EOF); } if (resume != null)