From bff695e397ea3405db66d1f3fe7dc7afcedcd07d Mon Sep 17 00:00:00 2001 From: Stephane Landelle Date: Tue, 7 Feb 2017 22:49:45 +0100 Subject: [PATCH] Drop WebSocketUpgradeHandler:: touchSuccess MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Motivation This hack was a very old workaround for #317 where the server would send the first frame along with the handshake. This issue has actually been fixed for quite some time, we just had to replace the `UpgradeCallback` with the future before triggering the read when upgrading the pipeline. We no longer need this protection as there’s no way the `UpgradeCallback` can be called twice. Modification: Remove dead code. Result: Clean code --- .../netty/handler/WebSocketHandler.java | 10 ++++------ .../asynchttpclient/ws/WebSocketUpgradeHandler.java | 6 ------ 2 files changed, 4 insertions(+), 12 deletions(-) diff --git a/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java b/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java index 9aa16fadd6..d86b0d9b82 100755 --- a/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java +++ b/client/src/main/java/org/asynchttpclient/netty/handler/WebSocketHandler.java @@ -73,12 +73,10 @@ public UpgradeCallback(NettyResponseFuture future, Channel channel, HttpRespo // We don't need to synchronize as replacing the "ws-decoder" will // process using the same thread. private void invokeOnSucces(Channel channel, WebSocketUpgradeHandler h) { - if (!h.touchSuccess()) { - try { - h.onSuccess(new NettyWebSocket(channel, responseHeaders.getHeaders())); - } catch (Exception ex) { - logger.warn("onSuccess unexpected exception", ex); - } + try { + h.onSuccess(new NettyWebSocket(channel, responseHeaders.getHeaders())); + } catch (Exception ex) { + logger.warn("onSuccess unexpected exception", ex); } } diff --git a/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java b/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java index 81853d1351..0888f7da2a 100644 --- a/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java +++ b/client/src/main/java/org/asynchttpclient/ws/WebSocketUpgradeHandler.java @@ -33,7 +33,6 @@ public class WebSocketUpgradeHandler implements UpgradeHandler, Async private WebSocket webSocket; private final List listeners; private final AtomicBoolean ok = new AtomicBoolean(false); - private boolean onSuccessCalled; private int status; private List bufferedFrames; @@ -53,11 +52,6 @@ public final void onThrowable(Throwable t) { onFailure(t); } - public boolean touchSuccess() { - boolean prev = onSuccessCalled; - onSuccessCalled = true; - return prev; - } @Override public final State onBodyPartReceived(HttpResponseBodyPart bodyPart) throws Exception {