Skip to content

Commit 9b7e091

Browse files
authored
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
1 parent b64abd0 commit 9b7e091

3 files changed

Lines changed: 32 additions & 3 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2012,7 +2012,8 @@ public void run() {
20122012
if (localHandshakePromise.isDone()) {
20132013
return;
20142014
}
2015-
SSLException exception = new SSLException("handshake timed out");
2015+
SSLException exception =
2016+
new SslHandshakeTimeoutException("handshake timed out after " + handshakeTimeoutMillis + "ms");
20162017
try {
20172018
if (localHandshakePromise.tryFailure(exception)) {
20182019
SslUtils.handleHandshakeFailure(ctx, exception, true);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Copyright 2020 The Netty Project
3+
*
4+
* The Netty Project licenses this file to you under the Apache License,
5+
* version 2.0 (the "License"); you may not use this file except in compliance
6+
* with the License. You may obtain a copy of the License at:
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13+
* License for the specific language governing permissions and limitations
14+
* under the License.
15+
*/
16+
package io.netty.handler.ssl;
17+
18+
import javax.net.ssl.SSLHandshakeException;
19+
20+
/**
21+
* {@link SSLHandshakeException} that is used when a handshake failed due a configured timeout.
22+
*/
23+
public final class SslHandshakeTimeoutException extends SSLHandshakeException {
24+
25+
SslHandshakeTimeoutException(String reason) {
26+
super(reason);
27+
}
28+
}

‎handler/src/test/java/io/netty/handler/ssl/SslHandlerTest.java‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,12 +194,12 @@ public boolean isActive() {
194194
assertFalse(ch.finishAndReleaseAll());
195195
}
196196

197-
@Test(expected = SSLException.class, timeout = 3000)
197+
@Test(expected = SslHandshakeTimeoutException.class, timeout = 3000)
198198
public void testClientHandshakeTimeout() throws Exception {
199199
testHandshakeTimeout(true);
200200
}
201201

202-
@Test(expected = SSLException.class, timeout = 3000)
202+
@Test(expected = SslHandshakeTimeoutException.class, timeout = 3000)
203203
public void testServerHandshakeTimeout() throws Exception {
204204
testHandshakeTimeout(false);
205205
}

0 commit comments

Comments
 (0)