Add SslHandshakeTimeoutException and use it for handshake timeouts (#10062)
Motivation: Often it is useful to be able to detect different sorts of SSL errors that cause the handshake to fail. To make this easier we should throw and explicit exception type for handshake timeouts. Modifications: - Add SslHandshakeTimeoutException (which extends SSLHandshakeException) and use it for handshake timeouts - Adjust testcases Result: Easier to detect that handshake failed because of a timeout
This commit is contained in:
parent
1c28cf3a14
commit
a1c5eb938c
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
@ -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);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user