Do not use static exceptions for websocket handshake timeout (#9174)

Motivation:

f17bfd0f64 removed the usage of static exception instances to reduce the risk of OOME due addSupressed calls. We should do the same for exceptions used to signal handshake timeouts.

Modifications:

Do not use static instances

Result:

No risk of OOME due addSuppressed calls
This commit is contained in:
Norman Maurer 2019-05-23 08:24:03 +02:00
parent 2e7e6d37d5
commit 5694dc3e2b
2 changed files with 3 additions and 12 deletions

View File

@ -24,7 +24,6 @@ import io.netty.handler.codec.http.FullHttpResponse;
import io.netty.handler.codec.http.websocketx.WebSocketClientProtocolHandler.ClientHandshakeStateEvent;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.internal.ThrowableUtil;
import java.util.concurrent.TimeUnit;
@ -32,10 +31,6 @@ import static io.netty.util.internal.ObjectUtil.*;
class WebSocketClientProtocolHandshakeHandler implements ChannelInboundHandler {
private static final WebSocketHandshakeException HANDSHAKE_TIMED_OUT_EXCEPTION = ThrowableUtil.unknownStackTrace(
new WebSocketHandshakeException("handshake timed out"),
WebSocketClientProtocolHandshakeHandler.class,
"channelActive(...)");
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MS = 10000L;
private final WebSocketClientHandshaker handshaker;
@ -109,7 +104,7 @@ class WebSocketClientProtocolHandshakeHandler implements ChannelInboundHandler {
return;
}
if (localHandshakePromise.tryFailure(HANDSHAKE_TIMED_OUT_EXCEPTION)) {
if (localHandshakePromise.tryFailure(new WebSocketHandshakeException("handshake timed out"))) {
ctx.flush()
.fireUserEventTriggered(ClientHandshakeStateEvent.HANDSHAKE_TIMEOUT)
.close();

View File

@ -30,7 +30,6 @@ import io.netty.handler.codec.http.websocketx.WebSocketServerProtocolHandler.Ser
import io.netty.handler.ssl.SslHandler;
import io.netty.util.concurrent.Future;
import io.netty.util.concurrent.FutureListener;
import io.netty.util.internal.ThrowableUtil;
import java.util.concurrent.TimeUnit;
@ -44,10 +43,6 @@ import static io.netty.util.internal.ObjectUtil.*;
* Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}.
*/
class WebSocketServerProtocolHandshakeHandler implements ChannelInboundHandler {
private static final WebSocketHandshakeException HANDSHAKE_TIMED_OUT_EXCEPTION = ThrowableUtil.unknownStackTrace(
new WebSocketHandshakeException("handshake timed out"),
WebSocketServerProtocolHandshakeHandler.class,
"channelRead(...)");
private static final long DEFAULT_HANDSHAKE_TIMEOUT_MS = 10000L;
@ -176,7 +171,8 @@ class WebSocketServerProtocolHandshakeHandler implements ChannelInboundHandler {
final Future<?> timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
if (localHandshakePromise.tryFailure(HANDSHAKE_TIMED_OUT_EXCEPTION)) {
if (!localHandshakePromise.isDone() &&
localHandshakePromise.tryFailure(new WebSocketHandshakeException("handshake timed out"))) {
ctx.flush()
.fireUserEventTriggered(ServerHandshakeStateEvent.HANDSHAKE_TIMEOUT)
.close();