Fix a bug with delegate/async SSL (#11537)
Motivation: This bug could occasionally cause SSL handshakes to time out, because the server-side handshake would fail to resume its event loop. Modification: Async delegate SSL tasks now lower their NEED_TASK status after they have executed, but before they run their completion callback. This is important because the completion callback could be querying the handshake status. This could cause the task delegator thread and the event look to race. If the event look queries the handshake status first, it might think that it still needs to delegate another task. If this happens, the delegator find a null task, and then fail to resume the event loop, causing the handshake to stall. Result: This data race no longer causes handshake timeouts.
This commit is contained in:
parent
8bcc27a169
commit
21df18deac
@ -1457,18 +1457,22 @@ public class ReferenceCountedOpenSslEngine extends SSLEngine implements Referenc
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(Runnable runnable) {
|
||||
public void run(final Runnable runnable) {
|
||||
if (isDestroyed()) {
|
||||
// The engine was destroyed in the meantime, just return.
|
||||
runnable.run();
|
||||
return;
|
||||
}
|
||||
try {
|
||||
task.runAsync(runnable);
|
||||
} finally {
|
||||
task.runAsync(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
// The task was run, reset needTask to false so getHandshakeStatus() returns the correct value.
|
||||
// This needs to be done before we run the completion runnable, since that might
|
||||
// query the handshake status.
|
||||
needTask = false;
|
||||
runnable.run();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user