Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoakim Erdfelt2015-03-18 23:20:50 +0000
committerJoakim Erdfelt2015-03-18 23:23:39 +0000
commite21d24b03586e16bc374e4f2a32793ffc27ddc9f (patch)
treee947a7c0fec18a1476f768ec8c4e2d3b4e3010a6 /jetty-websocket
parenta9be633816e36823959c988787ac3ab213d6e58d (diff)
downloadorg.eclipse.jetty.project-e21d24b03586e16bc374e4f2a32793ffc27ddc9f.tar.gz
org.eclipse.jetty.project-e21d24b03586e16bc374e4f2a32793ffc27ddc9f.tar.xz
org.eclipse.jetty.project-e21d24b03586e16bc374e4f2a32793ffc27ddc9f.zip
454934 - WebSocketClient / connectToServer can block indefinitely during upgrade failure
+ Handling EOF and Timeout in a clearer way inside UpgradeConnection
Diffstat (limited to 'jetty-websocket')
-rw-r--r--jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java38
-rw-r--r--jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties1
2 files changed, 37 insertions, 2 deletions
diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
index b8a20c3efb..7bb0bd2769 100644
--- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
+++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/io/UpgradeConnection.java
@@ -18,6 +18,7 @@
package org.eclipse.jetty.websocket.client.io;
+import java.io.EOFException;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
@@ -128,6 +129,12 @@ public class UpgradeConnection extends AbstractConnection
}
}
+ private void failUpgrade(Throwable cause)
+ {
+ close();
+ connectPromise.failed(cause);
+ }
+
private void notifyConnect(ClientUpgradeResponse response)
{
connectPromise.setResponse(response);
@@ -142,6 +149,10 @@ public class UpgradeConnection extends AbstractConnection
@Override
public void onFillable()
{
+ if (LOG.isDebugEnabled())
+ {
+ LOG.debug("onFillable");
+ }
ByteBuffer buffer = bufferPool.acquire(getInputBufferSize(),false);
BufferUtil.clear(buffer);
boolean readMore = false;
@@ -164,9 +175,31 @@ public class UpgradeConnection extends AbstractConnection
public void onOpen()
{
super.onOpen();
- // TODO: handle timeout?
getExecutor().execute(new SendUpgradeRequest());
}
+
+ @Override
+ public void onClose()
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.warn("Closed connection {}",this);
+ }
+ super.onClose();
+ }
+
+ @Override
+ protected boolean onReadTimeout()
+ {
+ if (LOG.isDebugEnabled())
+ {
+ LOG.warn("Timeout on connection {}",this);
+ }
+
+ failUpgrade(new IOException("Timeout while performing WebSocket Upgrade"));
+
+ return super.onReadTimeout();
+ }
/**
* Read / Parse the waiting read/fill buffer
@@ -189,7 +222,8 @@ public class UpgradeConnection extends AbstractConnection
}
else if (filled < 0)
{
- LOG.debug("read - EOF Reached");
+ LOG.warn("read - EOF Reached");
+ failUpgrade(new EOFException("Reading WebSocket Upgrade response"));
return false;
}
else
diff --git a/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties b/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties
index 9668b13105..a5afe1edb3 100644
--- a/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties
+++ b/jetty-websocket/websocket-client/src/test/resources/jetty-logging.properties
@@ -1,6 +1,7 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
org.eclipse.jetty.LEVEL=WARN
# org.eclipse.jetty.LEVEL=DEBUG
+# org.eclipse.jetty.io.LEVEL=DEBUG
# org.eclipse.jetty.io.ChannelEndPoint.LEVEL=DEBUG
# org.eclipse.jetty.io.SelectChannelEndPoint.LEVEL=DEBUG
# org.eclipse.jetty.io.IdleTimeout.LEVEL=DEBUG

Back to the top