Skip to content

Commit aacd6bb

Browse files
authored
Merge pull request #137 from tls-attacker/fix-thread-safety-issue-65
Fix thread safety issue in ThreadedScanJobExecutor
2 parents 01eff7c + bef7aee commit aacd6bb

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/main/java/de/rub/nds/scanner/core/execution/ThreadedScanJobExecutor.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.LinkedList;
2222
import java.util.List;
2323
import java.util.concurrent.*;
24+
import java.util.concurrent.atomic.AtomicInteger;
2425
import org.apache.logging.log4j.LogManager;
2526
import org.apache.logging.log4j.Logger;
2627

@@ -56,8 +57,8 @@ public class ThreadedScanJobExecutor<
5657
// Used for waiting for Threads in the ThreadPoolExecutor
5758
private final Semaphore semaphore;
5859

59-
private int probeCount;
60-
private int finishedProbes = 0;
60+
private volatile int probeCount;
61+
private final AtomicInteger finishedProbes = new AtomicInteger(0);
6162

6263
/**
6364
* Creates a new ThreadedScanJobExecutor with a custom thread pool.
@@ -140,13 +141,13 @@ private void executeProbesTillNoneCanBeExecuted(ReportT report) throws Interrupt
140141
List<Future<ScannerProbe<ReportT, StateT>>> finishedFutures = new ArrayList<>();
141142
for (Future<ScannerProbe<ReportT, StateT>> result : new ArrayList<>(futureResults)) {
142143
if (result.isDone()) {
143-
finishedProbes++;
144+
int currentFinishedProbes = finishedProbes.incrementAndGet();
144145
ScannerProbe<ReportT, StateT> probeResult = null;
145146
try {
146147
probeResult = result.get();
147148
LOGGER.info(
148149
"[{}/{}] {} probe executed",
149-
finishedProbes,
150+
currentFinishedProbes,
150151
probeCount,
151152
probeResult.getType().getName());
152153
} catch (ExecutionException e) {

0 commit comments

Comments
 (0)