Skip to content

Commit

Permalink
StacklessSSLHandshakeException: add a short stack-trace (netty#13315)
Browse files Browse the repository at this point in the history
Motivation:

Currently, `StacklessSSLHandshakeException` doesn't have any stack-trace
which makes it harder to understand where it comes from.

Modifications:

- Add one-line stack-trace using `ThrowableUtil.unknownStackTrace`
utility;

Result:

Similar to `StacklessClosedChannelException`,
`StacklessSSLHandshakeException` always has one-line stack-trace to
indicate where it was originated.
  • Loading branch information
idelpivnitskiy committed Apr 1, 2023
1 parent e56918e commit 1ea5ea6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
6 changes: 4 additions & 2 deletions handler/src/main/java/io/netty5/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import io.netty5.util.concurrent.Promise;
import io.netty5.util.internal.PlatformDependent;
import io.netty5.util.internal.SilentDispose;
import io.netty5.util.internal.ThrowableUtil;
import io.netty5.util.internal.UnstableApi;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -902,8 +903,9 @@ public void channelInactive(ChannelHandlerContext ctx) throws Exception {

// Add a supressed exception if the handshake was not completed yet.
if (isStateSet(STATE_HANDSHAKE_STARTED) && !handshakePromise.isDone()) {
exception.addSuppressed(
new StacklessSSLHandshakeException("Connection closed while SSL/TLS handshake was in progress"));
exception.addSuppressed(StacklessSSLHandshakeException.newInstance(
"Connection closed while SSL/TLS handshake was in progress",
SslHandler.class, "channelInactive"));
}

// Make sure to release SSLEngine,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
*/
package io.netty5.handler.ssl;

import io.netty5.util.internal.ThrowableUtil;

import javax.net.ssl.SSLHandshakeException;

/**
Expand All @@ -24,13 +26,7 @@ final class StacklessSSLHandshakeException extends SSLHandshakeException {

private static final long serialVersionUID = -1244781947804415549L;

/**
* Constructs an exception reporting an error found by
* an SSL subsystem during handshaking.
*
* @param reason describes the problem.
*/
StacklessSSLHandshakeException(String reason) {
private StacklessSSLHandshakeException(String reason) {
super(reason);
}

Expand All @@ -40,4 +36,11 @@ public Throwable fillInStackTrace() {
// stack trace as this is a stackless exception.
return this;
}

/**
* Creates a new {@link StacklessSSLHandshakeException} which has the origin of the given {@link Class} and method.
*/
static StacklessSSLHandshakeException newInstance(String reason, Class<?> clazz, String method) {
return ThrowableUtil.unknownStackTrace(new StacklessSSLHandshakeException(reason), clazz, method);
}
}

0 comments on commit 1ea5ea6

Please sign in to comment.