Skip to content

Commit bb0e561

Browse files
Sniffer: Fix potential infinite loop (#4726)
Co-authored-by: 风扇滑翔翼 <Fangliding.fshxy@outlook.com>
1 parent 09d84c4 commit bb0e561

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

app/dispatcher/default.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,10 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
371371
return nil, ctx.Err()
372372
default:
373373
cachingStartingTimeStamp := time.Now()
374-
cacheErr := cReader.Cache(payload, cacheDeadline)
374+
err := cReader.Cache(payload, cacheDeadline)
375+
if err != nil {
376+
return nil, err
377+
}
375378
cachingTimeElapsed := time.Since(cachingStartingTimeStamp)
376379
cacheDeadline -= cachingTimeElapsed
377380

@@ -381,12 +384,12 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
381384
case common.ErrNoClue: // No Clue: protocol not matches, and sniffer cannot determine whether there will be a match or not
382385
totalAttempt++
383386
case protocol.ErrProtoNeedMoreData: // Protocol Need More Data: protocol matches, but need more data to complete sniffing
384-
if cacheErr != nil { // Cache error (e.g. timeout) counts for failed attempt
385-
totalAttempt++
386-
}
387+
// in this case, do not add totalAttempt(allow to read until timeout)
387388
default:
388389
return result, err
389390
}
391+
} else {
392+
totalAttempt++
390393
}
391394
if totalAttempt >= 2 || cacheDeadline <= 0 {
392395
return nil, errSniffingTimeout

0 commit comments

Comments
 (0)