From e578791518b9ee722559b259cac95604f9415a63 Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Wed, 8 Jun 2022 10:44:17 +1000 Subject: [PATCH] Changes from review Signed-off-by: Lachlan Roberts --- .../org/eclipse/jetty/websocket/core/Extension.java | 7 +++++-- .../websocket/core/internal/ExtensionStack.java | 12 ++++++++++-- .../jetty/websocket/core/internal/FrameFlusher.java | 1 + .../core/internal/PerMessageDeflateExtension.java | 10 +++++++++- .../websocket/core/internal/TransformingFlusher.java | 5 +++++ 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/Extension.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/Extension.java index 0fdef6840ac..4d918e25ffe 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/Extension.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/Extension.java @@ -13,12 +13,15 @@ package org.eclipse.jetty.websocket.core; +import java.io.Closeable; +import java.io.IOException; + /** * Interface for WebSocket Extensions. *

* That {@link Frame}s are passed through the Extension via the {@link IncomingFrames} and {@link OutgoingFrames} interfaces */ -public interface Extension extends IncomingFrames, OutgoingFrames +public interface Extension extends IncomingFrames, OutgoingFrames, Closeable { void init(ExtensionConfig config, WebSocketComponents components); @@ -26,7 +29,7 @@ public interface Extension extends IncomingFrames, OutgoingFrames /** * Used to clean up any resources after connection close. */ - default void close() + default void close() throws IOException { } diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java index aafd22d812b..b894877b8b1 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/ExtensionStack.java @@ -62,9 +62,17 @@ public class ExtensionStack implements IncomingFrames, OutgoingFrames, Dumpable public void close() { - for (Extension e : extensions) + for (Extension ext : extensions) { - e.close(); + try + { + ext.close(); + } + catch (Throwable t) + { + if (LOG.isDebugEnabled()) + LOG.debug("Extension Error During Close", t); + } } } diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java index 9122cac4db7..e157ce65177 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/FrameFlusher.java @@ -184,6 +184,7 @@ public class FrameFlusher extends IteratingCallback { try (AutoLock l = lock.lock()) { + // TODO: find a way to not create exception if cause is null. closedCause = cause == null ? new ClosedChannelException() { @Override diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java index 2e9d2723bef..a39f6caf08a 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/PerMessageDeflateExtension.java @@ -151,7 +151,15 @@ public class PerMessageDeflateExtension extends AbstractExtension implements Dem public void close() { // TODO: use IteratingCallback.close() instead of creating exception with failFlusher methods. - ClosedChannelException exception = new ClosedChannelException(); + ClosedChannelException exception = new ClosedChannelException() + { + @Override + public Throwable fillInStackTrace() + { + return this; + } + }; + incomingFlusher.close(); incomingFlusher.failFlusher(exception); outgoingFlusher.failFlusher(exception); releaseInflater(); diff --git a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/TransformingFlusher.java b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/TransformingFlusher.java index 52dcad1e9f3..5bed90a3d44 100644 --- a/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/TransformingFlusher.java +++ b/jetty-websocket/websocket-core-common/src/main/java/org/eclipse/jetty/websocket/core/internal/TransformingFlusher.java @@ -83,6 +83,7 @@ public abstract class TransformingFlusher */ public void failFlusher(Throwable t) { + // TODO: find a way to close the flusher in non error case without exception. boolean failed = false; try (AutoLock l = lock.lock()) { @@ -91,6 +92,10 @@ public abstract class TransformingFlusher failure = t; failed = true; } + else + { + failure.addSuppressed(t); + } } if (failed)