diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java index 818287a362..e859b77755 100644 --- a/handler/src/main/java/io/netty/handler/ssl/SslHandler.java +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandler.java @@ -1991,7 +1991,8 @@ public class SslHandler extends ByteToMessageDecoder { return; } - SSLException exception = new SSLException("handshake timed out"); + SSLException exception = + new SslHandshakeTimeoutException("handshake timed out after " + handshakeTimeoutMillis + "ms"); try { if (localHandshakePromise.tryFailure(exception)) { SslUtils.handleHandshakeFailure(ctx, exception, true); diff --git a/handler/src/main/java/io/netty/handler/ssl/SslHandshakeTimeoutException.java b/handler/src/main/java/io/netty/handler/ssl/SslHandshakeTimeoutException.java new file mode 100644 index 0000000000..fbddbcc2b3 --- /dev/null +++ b/handler/src/main/java/io/netty/handler/ssl/SslHandshakeTimeoutException.java @@ -0,0 +1,28 @@ +/* + * Copyright 2020 The Netty Project + * + * The Netty Project licenses this file to you under the Apache License, + * version 2.0 (the "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at: + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations + * under the License. + */ +package io.netty.handler.ssl; + +import javax.net.ssl.SSLHandshakeException; + +/** + * {@link SSLHandshakeException} that is used when a handshake failed due a configured timeout. + */ +public final class SslHandshakeTimeoutException extends SSLHandshakeException { + + SslHandshakeTimeoutException(String reason) { + super(reason); + } +} diff --git a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java index d94a9c5e65..9f06c683bd 100644 --- a/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java +++ b/handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java @@ -55,14 +55,12 @@ import io.netty.util.concurrent.FutureListener; import io.netty.util.concurrent.ImmediateEventExecutor; import io.netty.util.concurrent.ImmediateExecutor; import io.netty.util.concurrent.Promise; -import io.netty.util.internal.PlatformDependent; import org.hamcrest.CoreMatchers; import org.junit.Test; import java.net.InetSocketAddress; import java.nio.channels.ClosedChannelException; import java.security.NoSuchAlgorithmException; -import java.util.List; import java.util.Queue; import java.util.concurrent.BlockingQueue; import java.util.concurrent.CompletionException; @@ -190,12 +188,12 @@ public class SslHandlerTest { assertFalse(ch.finishAndReleaseAll()); } - @Test(expected = SSLException.class, timeout = 3000) + @Test(expected = SslHandshakeTimeoutException.class, timeout = 3000) public void testClientHandshakeTimeout() throws Throwable { testHandshakeTimeout(true); } - @Test(expected = SSLException.class, timeout = 3000) + @Test(expected = SslHandshakeTimeoutException.class, timeout = 3000) public void testServerHandshakeTimeout() throws Throwable { testHandshakeTimeout(false); }