Issue #7286 - fix potential issue with websocket write timeout
Let websocket-core handle any idleTimeout & writeTimeouts instead of bad attempt to do it in Jetty/Javax API layers. Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
parent
6b2db685cd
commit
b2b7517297
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
import java.io.Writer;
|
import java.io.Writer;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.websocket.EncodeException;
|
import javax.websocket.EncodeException;
|
||||||
import javax.websocket.RemoteEndpoint;
|
import javax.websocket.RemoteEndpoint;
|
||||||
|
|
||||||
|
@ -64,7 +63,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
|
||||||
|
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(new Frame(OpCode.BINARY).setPayload(data), b, false);
|
sendFrame(new Frame(OpCode.BINARY).setPayload(data), b, false);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -96,7 +95,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
|
||||||
frame.setFin(isLast);
|
frame.setFin(isLast);
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(frame, b, false);
|
sendFrame(frame, b, false);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -104,7 +103,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
super.sendObject(data, b);
|
super.sendObject(data, b);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -118,7 +117,7 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
|
||||||
|
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(new Frame(OpCode.TEXT).setPayload(text), b, false);
|
sendFrame(new Frame(OpCode.TEXT).setPayload(text), b, false);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -150,12 +149,6 @@ public class JavaxWebSocketBasicRemote extends JavaxWebSocketRemoteEndpoint impl
|
||||||
frame.setFin(isLast);
|
frame.setFin(isLast);
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(frame, b, false);
|
sendFrame(frame, b, false);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
|
||||||
|
|
||||||
private long getBlockingTimeout()
|
|
||||||
{
|
|
||||||
long idleTimeout = getIdleTimeout();
|
|
||||||
return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,7 +16,6 @@ package org.eclipse.jetty.websocket.javax.common;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
import javax.websocket.EncodeException;
|
import javax.websocket.EncodeException;
|
||||||
import javax.websocket.Encoder;
|
import javax.websocket.Encoder;
|
||||||
import javax.websocket.SendHandler;
|
import javax.websocket.SendHandler;
|
||||||
|
@ -64,7 +63,7 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
coreSession.flush(b);
|
coreSession.flush(b);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -226,7 +225,7 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo
|
||||||
|
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(new Frame(OpCode.PING).setPayload(data), b, batch);
|
sendFrame(new Frame(OpCode.PING).setPayload(data), b, batch);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -237,7 +236,7 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo
|
||||||
|
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendFrame(new Frame(OpCode.PONG).setPayload(data), b, batch);
|
sendFrame(new Frame(OpCode.PONG).setPayload(data), b, batch);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertMessageNotNull(Object data)
|
protected void assertMessageNotNull(Object data)
|
||||||
|
@ -255,10 +254,4 @@ public class JavaxWebSocketRemoteEndpoint implements javax.websocket.RemoteEndpo
|
||||||
throw new IllegalArgumentException("SendHandler cannot be null");
|
throw new IllegalArgumentException("SendHandler cannot be null");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private long getBlockingTimeout()
|
|
||||||
{
|
|
||||||
long idleTimeout = getIdleTimeout();
|
|
||||||
return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@ import java.io.IOException;
|
||||||
import java.net.SocketAddress;
|
import java.net.SocketAddress;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
import java.util.concurrent.TimeUnit;
|
|
||||||
|
|
||||||
import org.eclipse.jetty.util.BufferUtil;
|
import org.eclipse.jetty.util.BufferUtil;
|
||||||
import org.eclipse.jetty.util.Callback;
|
import org.eclipse.jetty.util.Callback;
|
||||||
|
@ -79,7 +78,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendPartialBytes(fragment, isLast, b);
|
sendPartialBytes(fragment, isLast, b);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -121,7 +120,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
sendPartialText(fragment, isLast, b);
|
sendPartialText(fragment, isLast, b);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: Remove the throws IOException from API for this method in the next major release.
|
// FIXME: Remove the throws IOException from API for this method in the next major release.
|
||||||
|
@ -189,7 +188,7 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
coreSession.sendFrame(frame, b, false);
|
coreSession.sendFrame(frame, b, false);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -232,12 +231,6 @@ public class JettyWebSocketRemoteEndpoint implements org.eclipse.jetty.websocket
|
||||||
{
|
{
|
||||||
FutureCallback b = new FutureCallback();
|
FutureCallback b = new FutureCallback();
|
||||||
coreSession.flush(b);
|
coreSession.flush(b);
|
||||||
b.block(getBlockingTimeout(), TimeUnit.MILLISECONDS);
|
b.block();
|
||||||
}
|
|
||||||
|
|
||||||
private long getBlockingTimeout()
|
|
||||||
{
|
|
||||||
long idleTimeout = coreSession.getIdleTimeout().toMillis();
|
|
||||||
return (idleTimeout > 0) ? idleTimeout + 1000 : idleTimeout;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue