Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,6 @@ public class MvnCliComponentDetector : FileComponentDetector
@"https?://[^\s\]\)>]+",
RegexOptions.Compiled | RegexOptions.IgnoreCase);

/// <summary>
/// Maximum time allowed for the OnPrepareDetectionAsync phase.
/// This is a safety guardrail to prevent hangs.
/// Most repos should complete the full Maven CLI scan within this window.
/// </summary>
private static readonly TimeSpan PrepareDetectionTimeout = TimeSpan.FromMinutes(5);

private readonly IMavenCommandService mavenCommandService;
private readonly IEnvironmentVariableService envVarService;
private readonly IFileUtilityService fileUtilityService;
Expand Down Expand Up @@ -298,20 +291,13 @@ protected override async Task<IObservable<ProcessRequest>> OnPrepareDetectionAsy
// This is critical because detectors are registered as singletons
this.ResetScanState();

// Wrap the entire method in a try-catch with timeout to protect against hangs.
// OnPrepareDetectionAsync doesn't have the same guardrails as OnFileFoundAsync,
// so we need to be extra careful here.
try
{
using var timeoutCts = new CancellationTokenSource(PrepareDetectionTimeout);
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);

return await this.OnPrepareDetectionCoreAsync(processRequests, linkedCts.Token);
return await this.OnPrepareDetectionCoreAsync(processRequests, cancellationToken);
}
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
catch (OperationCanceledException)
{
// Timeout occurred (not user cancellation)
this.LogWarning($"OnPrepareDetectionAsync timed out after {PrepareDetectionTimeout.TotalMinutes} minutes. Falling back to static pom.xml parsing.");
this.LogWarning("OnPrepareDetectionAsync was cancelled. Falling back to static pom.xml parsing.");
this.Telemetry["TimedOut"] = "true";
this.fallbackReason = MavenFallbackReason.OtherMvnCliFailure;
this.usedDetectionMethod = MavenDetectionMethod.Mixed;
Expand Down
Loading