Skip to content

Commit

Permalink
Add SslHandshakeTimeoutException and use it for handshake timeouts (#…
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
normanmaurer committed Feb 27, 2020
1 parent b64abd0 commit 9b7e091
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 3 deletions.
3 changes: 2 additions & 1 deletion handler/src/main/java/io/netty/handler/ssl/SslHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2012,7 +2012,8 @@ public void run() {
if (localHandshakePromise.isDone()) {
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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,12 @@ public boolean isActive() {
assertFalse(ch.finishAndReleaseAll());
}

@Test(expected = SSLException.class, timeout = 3000)
@Test(expected = SslHandshakeTimeoutException.class, timeout = 3000)
public void testClientHandshakeTimeout() throws Exception {
testHandshakeTimeout(true);
}

@Test(expected = SSLException.class, timeout = 3000)
@Test(expected = SslHandshakeTimeoutException.class, timeout = 3000)
public void testServerHandshakeTimeout() throws Exception {
testHandshakeTimeout(false);
}
Expand Down

0 comments on commit 9b7e091

Please sign in to comment.