Skip to content

Commit 3014a65

Browse files
feat: add comprehensive context diagnostic logging
Add detailed context status logging throughout scan execution pipeline to diagnose timeout issues: - Log context deadline and remaining time before Nmap execution - Check context cancellation status before each Nmap.Scan() call - Log context status before and during testing phase - Verify parent context health after discovery phase This will help identify whether context timeout is the root cause of Nmap failures or if there's context contamination/replacement happening. Related to adversarial collaboration investigation of 'context deadline exceeded' errors despite parent context having time remaining.
1 parent 63f8bb8 commit 3014a65

2 files changed

Lines changed: 41 additions & 0 deletions

File tree

internal/discovery/engine.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ func (e *Engine) ListSessions() []*DiscoverySession {
226226
}
227227

228228
// runDiscovery runs the discovery process
229+
// TODO P0: This should accept context.Context parameter from parent to respect timeout chain
230+
// Currently uses context.Background() which ignores parent cancellation
229231
func (e *Engine) runDiscovery(session *DiscoverySession) {
230232
start := time.Now()
231233
ctx, cancel := context.WithTimeout(context.Background(), e.config.Timeout)

internal/orchestrator/bounty_engine.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,20 @@ func (e *BugBountyEngine) Execute(ctx context.Context, target string) (*BugBount
408408

409409
// Phase 3: Vulnerability Testing (parallel)
410410
tracker.StartPhase("testing")
411+
412+
// DIAGNOSTIC: Check context status before testing
413+
select {
414+
case <-ctx.Done():
415+
e.logger.Errorw("DIAGNOSTIC: Context already cancelled before testing phase",
416+
"error", ctx.Err(),
417+
"elapsed_time", time.Since(result.StartTime),
418+
)
419+
default:
420+
e.logger.Infow("DIAGNOSTIC: Context still valid before testing phase",
421+
"elapsed_time", time.Since(result.StartTime),
422+
)
423+
}
424+
411425
findings, phaseResults := e.executeTestingPhase(ctx, target, prioritized, tracker)
412426
for phase, pr := range phaseResults {
413427
result.PhaseResults[phase] = pr
@@ -1209,6 +1223,18 @@ func (e *BugBountyEngine) runNmapScans(ctx context.Context, assets []*AssetPrior
12091223

12101224
e.logger.Infow("Running Nmap service fingerprinting")
12111225

1226+
// DIAGNOSTIC: Check context before Nmap execution
1227+
if deadline, ok := ctx.Deadline(); ok {
1228+
remaining := time.Until(deadline)
1229+
e.logger.Infow("DIAGNOSTIC: Context deadline before Nmap execution",
1230+
"deadline", deadline,
1231+
"remaining_seconds", remaining.Seconds(),
1232+
"remaining_duration", remaining.String(),
1233+
)
1234+
} else {
1235+
e.logger.Warnw("DIAGNOSTIC: No deadline on context before Nmap - this is unexpected!")
1236+
}
1237+
12121238
var findings []types.Finding
12131239

12141240
// Scan each asset's host
@@ -1226,6 +1252,19 @@ func (e *BugBountyEngine) runNmapScans(ctx context.Context, assets []*AssetPrior
12261252
"component", "nmap_scanner",
12271253
)
12281254

1255+
// DIAGNOSTIC: Check context status immediately before each Nmap call
1256+
select {
1257+
case <-ctx.Done():
1258+
e.logger.Errorw("DIAGNOSTIC: Context already cancelled before Nmap.Scan()",
1259+
"error", ctx.Err(),
1260+
"host", host,
1261+
)
1262+
default:
1263+
e.logger.Debugw("DIAGNOSTIC: Context still valid before Nmap.Scan()",
1264+
"host", host,
1265+
)
1266+
}
1267+
12291268
// Run Nmap scan
12301269
results, err := e.nmapScanner.Scan(ctx, host, nil)
12311270
if err != nil {

0 commit comments

Comments
 (0)