Skip to content

Commit

Permalink
SSL: Hold the right monitor wheile running delegating task (#13875)
Browse files Browse the repository at this point in the history
Motivation:

We need to ensure we hold the correct lock when we execute the
delegating task to guard against possible concurrent shutdown of the
engine.

Modifications:

- Fix incorrect synchronized block

Result:

Hold correct lock
  • Loading branch information
normanmaurer committed Feb 28, 2024
1 parent ee6bc34 commit 2c965b1
Showing 1 changed file with 13 additions and 10 deletions.
Expand Up @@ -57,7 +57,6 @@
import java.security.AlgorithmConstraints;
import java.security.Principal;
import java.security.cert.Certificate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
Expand Down Expand Up @@ -1469,16 +1468,20 @@ public void run(Runnable runnable) {
}
}

private synchronized void runAndResetNeedTask(Runnable task) {
try {
if (isDestroyed()) {
// The engine was destroyed in the meantime, just return.
return;
private void runAndResetNeedTask(Runnable task) {
// We need to synchronize on the ReferenceCountedOpenSslEngine, we are sure the SSL object
// will not be freed by the user calling for example shutdown() concurrently.
synchronized (ReferenceCountedOpenSslEngine.this) {
try {
if (isDestroyed()) {
// The engine was destroyed in the meantime, just return.
return;
}
task.run();
} finally {
// The task was run, reset needTask to false so getHandshakeStatus() returns the correct value.
needTask = false;
}
task.run();
} finally {
// The task was run, reset needTask to false so getHandshakeStatus() returns the correct value.
needTask = false;
}
}

Expand Down

0 comments on commit 2c965b1

Please sign in to comment.