GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Fixed: Call `handshakeFailure` for TLS timeouts and early closes (#18… · netty/netty@418ec43

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • handler/src
    • main/java/io/netty/handler/ssl
      • ApplicationProtocolNegotiationHandler.java
    • test/java/io/netty/handler/ssl
      • ApplicationProtocolNegotiationHandlerTest.java
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java‎

Copy file name to clipboardExpand all lines: handler/src/main/java/io/netty/handler/ssl/ApplicationProtocolNegotiationHandler.java
+23-13Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import io.netty.util.internal.logging.InternalLogger;
2828
import io.netty.util.internal.logging.InternalLoggerFactory;
2929

30+
import java.nio.channels.ClosedChannelException;
3031
import javax.net.ssl.SSLException;
3132

3233
/**
@@ -139,19 +140,24 @@ public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exc
139140
String protocol = sslHandler.applicationProtocol();
140141
configurePipeline(ctx, protocol != null ? protocol : fallbackProtocol);
141142
} else {
142-
try {
143-
super.userEventTriggered(ctx, evt);
144-
} finally {
145-
this.notifyHandshakeFailure(ctx, handshakeEvent.cause());
143+
// timeouts and early closes may not produce a decoder exception
144+
// preserve the existing exception and close handling for other TLS failures
145+
Throwable cause = handshakeEvent.cause();
146+
if (cause instanceof SslHandshakeTimeoutException || cause instanceof ClosedChannelException) {
147+
try {
148+
super.userEventTriggered(ctx, evt);
149+
} finally {
150+
notifyHandshakeFailure(ctx, cause);
151+
}
152+
153+
return;
146154
}
147-
148-
return;
149155
}
150156
} catch (Throwable cause) {
151157
exceptionCaught(ctx, cause);
152158
} finally {
153-
// consume later SSL decoder exceptions to avoid downstream warnings
154-
// see https://github.com/netty/netty/issues/10342; timeouts and early closes may only emit this event
159+
// keep the handler after failure to consume later SSL decoder exceptions
160+
// see https://github.com/netty/netty/issues/10342
155161
if (handshakeEvent.isSuccess()) {
156162
removeSelfIfPresent(ctx);
157163
}
@@ -197,9 +203,14 @@ protected void handshakeFailure(ChannelHandlerContext ctx, Throwable cause) thro
197203
}
198204

199205
private void notifyHandshakeFailure(ChannelHandlerContext ctx, Throwable cause) throws Exception {
200-
if (!this.handshakeFailed) {
201-
this.handshakeFailed = true;
202-
this.handshakeFailure(ctx, cause);
206+
if (!handshakeFailed) {
207+
handshakeFailed = true;
208+
209+
try {
210+
handshakeFailure(ctx, cause);
211+
} catch (Throwable innerCause) {
212+
exceptionCaught(ctx, innerCause);
213+
}
203214
}
204215
}
205216

@@ -208,13 +219,12 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E
208219
Throwable wrapped;
209220
if (cause instanceof DecoderException && ((wrapped = cause.getCause()) instanceof SSLException)) {
210221
try {
211-
this.notifyHandshakeFailure(ctx, wrapped);
222+
notifyHandshakeFailure(ctx, wrapped);
212223
return;
213224
} finally {
214225
removeSelfIfPresent(ctx);
215226
}
216227
}
217-
218228
logger.warn("{} Failed to select the application-level protocol:", ctx.channel(), cause);
219229
ctx.fireExceptionCaught(cause);
220230
ctx.close();

0 commit comments

Comments
0 (0)
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.