Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UNDERTOW-2304] SslConduit.doUnwrap loop protection #1512

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions core/src/main/java/io/undertow/UndertowLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -458,4 +458,8 @@ void nodeConfigCreated(URI connectionURI, String balancer, String domain, String
@LogMessage(level = WARN)
@Message(id = 5102, value = "Flushing waiting in a frame more than %s miliseconds. The framed channel will be forcibly closed.")
void noFrameflushInTimeout(long timeoutMiliseconds);

@LogMessage(level = ERROR)
@Message(id = 5103, value = "SSL outstanding task loop detected in doWrap/doUnwrap calls. This is indicative of task thread exhaustion so consider investigating any slowness and thread ehxaustion concerns via thread dumps and increasing task-max-threads as needed. Current state %s")
void sslTaskLoopDetected(SslConduit sslConduit);
}
17 changes: 17 additions & 0 deletions core/src/main/java/io/undertow/protocols/ssl/SslConduit.java
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ public class SslConduit implements StreamSourceConduit, StreamSinkConduit {
private SslWriteReadyHandler writeReadyHandler;
private SslReadReadyHandler readReadyHandler;
private int readListenerInvocationCount;
private int outstandingTaskWaitCount;

private boolean invokingReadListenerHandshake = false;

Expand Down Expand Up @@ -710,7 +711,15 @@ private synchronized long doUnwrap(ByteBuffer[] userBuffers, int off, int len) t
throw new ClosedChannelException();
}
if(outstandingTasks > 0) {
if(outstandingTaskWaitCount++ == MAX_READ_LISTENER_INVOCATIONS) {
UndertowLogger.REQUEST_LOGGER.sslTaskLoopDetected(this);
IoUtils.safeClose(connection, delegate);
close();
return -1;
}
return 0;
} else {
outstandingTaskWaitCount = 0;
}
if(anyAreSet(state, FLAG_READ_REQUIRES_WRITE)) {
doWrap(null, 0, 0);
Expand Down Expand Up @@ -919,7 +928,15 @@ private synchronized long doWrap(ByteBuffer[] userBuffers, int off, int len) thr
throw new ClosedChannelException();
}
if(outstandingTasks > 0) {
if(outstandingTaskWaitCount++ == MAX_READ_LISTENER_INVOCATIONS) {
UndertowLogger.REQUEST_LOGGER.sslTaskLoopDetected(this);
IoUtils.safeClose(connection, delegate);
close();
return -1;
}
return 0;
} else {
outstandingTaskWaitCount = 0;
}
if(anyAreSet(state, FLAG_WRITE_REQUIRES_READ)) {
doUnwrap(null, 0, 0);
Expand Down
Loading