Skip to content

Commit c3ef82c

Browse files
authored
Bump mvn cli detector timeout to 9 min (#1771)
* Make mvn cli component respect cancellation token
1 parent f40d70c commit c3ef82c

1 file changed

Lines changed: 3 additions & 17 deletions

File tree

src/Microsoft.ComponentDetection.Detectors/maven/MvnCliComponentDetector.cs

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,6 @@ public class MvnCliComponentDetector : FileComponentDetector
101101
@"https?://[^\s\]\)>]+",
102102
RegexOptions.Compiled | RegexOptions.IgnoreCase);
103103

104-
/// <summary>
105-
/// Maximum time allowed for the OnPrepareDetectionAsync phase.
106-
/// This is a safety guardrail to prevent hangs.
107-
/// Most repos should complete the full Maven CLI scan within this window.
108-
/// </summary>
109-
private static readonly TimeSpan PrepareDetectionTimeout = TimeSpan.FromMinutes(5);
110-
111104
private readonly IMavenCommandService mavenCommandService;
112105
private readonly IEnvironmentVariableService envVarService;
113106
private readonly IFileUtilityService fileUtilityService;
@@ -298,20 +291,13 @@ protected override async Task<IObservable<ProcessRequest>> OnPrepareDetectionAsy
298291
// This is critical because detectors are registered as singletons
299292
this.ResetScanState();
300293

301-
// Wrap the entire method in a try-catch with timeout to protect against hangs.
302-
// OnPrepareDetectionAsync doesn't have the same guardrails as OnFileFoundAsync,
303-
// so we need to be extra careful here.
304294
try
305295
{
306-
using var timeoutCts = new CancellationTokenSource(PrepareDetectionTimeout);
307-
using var linkedCts = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken, timeoutCts.Token);
308-
309-
return await this.OnPrepareDetectionCoreAsync(processRequests, linkedCts.Token);
296+
return await this.OnPrepareDetectionCoreAsync(processRequests, cancellationToken);
310297
}
311-
catch (OperationCanceledException) when (!cancellationToken.IsCancellationRequested)
298+
catch (OperationCanceledException)
312299
{
313-
// Timeout occurred (not user cancellation)
314-
this.LogWarning($"OnPrepareDetectionAsync timed out after {PrepareDetectionTimeout.TotalMinutes} minutes. Falling back to static pom.xml parsing.");
300+
this.LogWarning("OnPrepareDetectionAsync was cancelled. Falling back to static pom.xml parsing.");
315301
this.Telemetry["TimedOut"] = "true";
316302
this.fallbackReason = MavenFallbackReason.OtherMvnCliFailure;
317303
this.usedDetectionMethod = MavenDetectionMethod.Mixed;

0 commit comments

Comments
 (0)