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:
parent
b11afd28f4
commit
137a3e7137
@ -24,18 +24,12 @@ 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.concurrent.ScheduledFuture;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static io.netty.util.internal.ObjectUtil.*;
|
||||
|
||||
class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
|
||||
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;
|
||||
@ -112,7 +106,7 @@ class WebSocketClientProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
|
||||
return;
|
||||
}
|
||||
|
||||
if (localHandshakePromise.tryFailure(HANDSHAKE_TIMED_OUT_EXCEPTION)) {
|
||||
if (localHandshakePromise.tryFailure(new WebSocketHandshakeException("handshake timed out"))) {
|
||||
ctx.flush()
|
||||
.fireUserEventTriggered(ClientHandshakeStateEvent.HANDSHAKE_TIMEOUT)
|
||||
.close();
|
||||
|
@ -30,8 +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.concurrent.ScheduledFuture;
|
||||
import io.netty.util.internal.ThrowableUtil;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@ -45,10 +43,6 @@ import static io.netty.util.internal.ObjectUtil.*;
|
||||
* Handles the HTTP handshake (the HTTP Upgrade request) for {@link WebSocketServerProtocolHandler}.
|
||||
*/
|
||||
class WebSocketServerProtocolHandshakeHandler extends ChannelInboundHandlerAdapter {
|
||||
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;
|
||||
|
||||
@ -180,7 +174,8 @@ class WebSocketServerProtocolHandshakeHandler extends ChannelInboundHandlerAdapt
|
||||
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();
|
||||
|
Loading…
Reference in New Issue
Block a user