From d95c825c5c8363988444eaf3e67e58fbdf6a38be Mon Sep 17 00:00:00 2001 From: Lachlan Roberts Date: Fri, 4 Oct 2019 11:13:38 +1000 Subject: [PATCH] Issue #3558 - only notify WS onError if onClose has not been called Signed-off-by: Lachlan Roberts --- .../eclipse/jetty/websocket/tests/ConcurrentConnectTest.java | 3 ++- .../org/eclipse/jetty/websocket/common/WebSocketSession.java | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java index 1351290d347..34e41ff26e1 100644 --- a/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java +++ b/jetty-websocket/jetty-websocket-tests/src/test/java/org/eclipse/jetty/websocket/tests/ConcurrentConnectTest.java @@ -41,6 +41,7 @@ import org.junit.jupiter.api.Test; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.is; +import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; public class ConcurrentConnectTest @@ -130,7 +131,7 @@ public class ConcurrentConnectTest assertTrue(l.closed.await(5, TimeUnit.SECONDS)); assertThat(l.closeCode, is(StatusCode.NORMAL)); assertThat(l.closeReason, is("close from client")); - //assertNull(l.failure); //TODO: we can get failures after close?? + assertNull(l.failure); } closeListener.closeLatch.await(5, TimeUnit.SECONDS); diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index 016a2f3f616..60edd8a178c 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -397,7 +397,10 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem } if (openFuture != null && !openFuture.isDone()) openFuture.completeExceptionally(cause); - websocket.onError(cause); + + // Only notify onError if onClose has not been called. + if (!onCloseCalled.get()) + websocket.onError(cause); } /**