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

Fix InterruptedException in projects with large dependency trees #419

Merged
Merged
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
7 changes: 4 additions & 3 deletions src/main/java/com/jfrog/ide/idea/scan/ScanManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import static com.jfrog.ide.common.utils.XrayConnectionUtils.createXrayClientBuilder;

public class ScanManager {
private final int SCAN_TIMEOUT_MINUTES = 10;
private final int SCAN_TIMEOUT_MINUTES = 60;
private final Project project;
private final ScannerFactory factory;
private final SourceCodeScannerManager sourceCodeScannerManager;
Expand Down Expand Up @@ -96,8 +96,9 @@ public void startScan() {
scanner.asyncScanAndUpdateResults();
}
executor.shutdown();
//noinspection ResultOfMethodCallIgnored
executor.awaitTermination(SCAN_TIMEOUT_MINUTES, TimeUnit.MINUTES);
if (!executor.awaitTermination(SCAN_TIMEOUT_MINUTES, TimeUnit.MINUTES)) {
logError(Logger.getInstance(), "Scan timeout of " + SCAN_TIMEOUT_MINUTES + " minutes elapsed. The scan is being canceled.", true);
}
// Cache tree only if no errors occurred during scan.
if (scanners.values().stream().anyMatch(ScannerBase::isScanInterrupted)) {
componentsTree.deleteCachedTree();
Expand Down
20 changes: 13 additions & 7 deletions src/main/java/com/jfrog/ide/idea/scan/ScannerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

import static com.jfrog.ide.common.log.Utils.logError;
Expand All @@ -75,6 +76,7 @@ public abstract class ScannerBase {
protected SourceCodeScannerManager sourceCodeScannerManager;
String basePath;
private ExecutorService executor;
private com.intellij.openapi.progress.ProgressIndicator progressIndicator;

/**
* @param project currently opened IntelliJ project. We'll use this project to retrieve project based services
Expand Down Expand Up @@ -295,6 +297,7 @@ public void run(@NotNull com.intellij.openapi.progress.ProgressIndicator indicat
log.info("Scan already in progress");
return;
}
progressIndicator = indicator;
scanAndUpdate(new ProgressIndicatorImpl(indicator));
}

Expand All @@ -311,7 +314,7 @@ public void onThrowable(@NotNull Throwable error) {
}

};
executor.submit(createRunnable(scanAndUpdateTask, latch, this.log));
executor.submit(createRunnable(scanAndUpdateTask, latch, progressIndicator, log));
}

/**
Expand All @@ -334,12 +337,13 @@ private String getTaskTitle() {
/**
* Create a runnable to be submitted to the executor service, or run directly.
*
* @param task - The task to submit
* @param latch - The countdown latch, which makes sure the executor service doesn't get more than 3 tasks.
* If null, the scan was initiated by a change in the project descriptor and the executor
* service is terminated. In this case, there is no requirement to wait.
* @param task The task to submit
* @param latch The countdown latch, which makes sure the executor service doesn't get more than 3 tasks.
* If null, the scan was initiated by a change in the project descriptor and the executor
* service is terminated. In this case, there is no requirement to wait.
* @param progressIndicator The task's {@link com.intellij.openapi.progress.ProgressIndicator} object.
*/
public static Runnable createRunnable(Task.Backgroundable task, CountDownLatch latch, Log log) {
public static Runnable createRunnable(Task.Backgroundable task, CountDownLatch latch, com.intellij.openapi.progress.ProgressIndicator progressIndicator, Log log) {
return () -> {
// The progress manager is only good for foreground threads.
if (SwingUtilities.isEventDispatchThread()) {
Expand All @@ -354,7 +358,9 @@ public static Runnable createRunnable(Task.Backgroundable task, CountDownLatch l
latch.await();
}
} catch (InterruptedException e) {
logError(log, ExceptionUtils.getRootCauseMessage(e), e, true);
// This exception is thrown when this thread is interrupted (e.g. when the scan timeout has elapsed).
logError(log, ExceptionUtils.getRootCauseMessage(e), e, false);
progressIndicator.cancel();
}
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class SourceCodeScannerManager {
protected Project project;
protected PackageManagerType packageType;
private static final String SKIP_FOLDERS_SUFFIX = "*/**";
private com.intellij.openapi.progress.ProgressIndicator progressIndicator;

public SourceCodeScannerManager(Project project) {
this.project = project;
Expand Down Expand Up @@ -113,6 +114,7 @@ public void run(@NotNull com.intellij.openapi.progress.ProgressIndicator indicat
log.info("Advanced source code scan is already in progress");
return;
}
progressIndicator = indicator;
sourceCodeScanAndUpdate(new ProgressIndicatorImpl(indicator), ProgressManager::checkCanceled, log);
}

Expand All @@ -128,7 +130,7 @@ public void onThrowable(@NotNull Throwable error) {
}

};
executor.submit(createRunnable(sourceCodeScanTask, latch, log));
executor.submit(createRunnable(sourceCodeScanTask, latch, progressIndicator, log));
}

private void sourceCodeScanAndUpdate(ProgressIndicator indicator, Runnable checkCanceled, Logger log) {
Expand Down
Loading