Fix issue with finishing handshake in ssl driver (#30580)

This is fixing an issue that has come up in some builds. In some
scenarios I see an assertion failure that we are trying to move to
application mode when we are not in handshake mode. What I think is
happening is that we are in handshake mode and have received the
completed handshake message AND an application message. While reading in
handshake mode we switch to application mode. However, there is still
data to be consumed so we attempt to continue to read in handshake mode.
This leads to us attempting to move to application mode again throwing
an assertion.

This commit fixes this by immediatly exiting the handshake mode read
method if we are not longer in handshake mode. Additionally if we swap
modes during a read we attempt to read with the new mode to see if there
is data that needs to be handled.
This commit is contained in:
Tim Brooks 2018-05-14 19:19:53 -06:00 committed by GitHub
parent 6517ac98eb
commit 848f240926
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -113,7 +113,13 @@ public class SSLDriver implements AutoCloseable {
}
public void read(InboundChannelBuffer buffer) throws SSLException {
Mode modePriorToRead;
do {
modePriorToRead = currentMode;
currentMode.read(buffer);
// If we switched modes we want to read again as there might be unhandled bytes that need to be
// handled by the new mode.
} while (modePriorToRead != currentMode);
}
public boolean readyForApplicationWrites() {
@ -365,8 +371,9 @@ public class SSLDriver implements AutoCloseable {
try {
SSLEngineResult result = unwrap(buffer);
handshakeStatus = result.getHandshakeStatus();
continueUnwrap = result.bytesConsumed() > 0;
handshake();
// If we are done handshaking we should exit the handshake read
continueUnwrap = result.bytesConsumed() > 0 && currentMode.isHandshake();
} catch (SSLException e) {
closingInternal();
throw e;