Skip to content

Commit 97d089e

Browse files
committed
Sniffer: fix infinite loop stuck
1 parent 72170d8 commit 97d089e

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

app/dispatcher/default.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dispatcher
22

33
import (
44
"context"
5+
"io"
56
"regexp"
67
"strings"
78
"sync"
@@ -374,6 +375,9 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
374375
default:
375376
cachingStartingTimeStamp := time.Now()
376377
cacheErr := cReader.Cache(payload, cacheDeadline)
378+
if cacheErr != nil {
379+
return nil, cacheErr
380+
}
377381
cachingTimeElapsed := time.Since(cachingStartingTimeStamp)
378382
cacheDeadline -= cachingTimeElapsed
379383

@@ -383,12 +387,12 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
383387
case common.ErrNoClue: // No Clue: protocol not matches, and sniffer cannot determine whether there will be a match or not
384388
totalAttempt++
385389
case protocol.ErrProtoNeedMoreData: // Protocol Need More Data: protocol matches, but need more data to complete sniffing
386-
if cacheErr != nil { // Cache error (e.g. timeout) counts for failed attempt
387-
totalAttempt++
388-
}
390+
totalAttempt++
389391
default:
390392
return result, err
391393
}
394+
} else {
395+
return nil, io.EOF
392396
}
393397
if totalAttempt >= 2 || cacheDeadline <= 0 {
394398
return nil, errSniffingTimeout

0 commit comments

Comments
 (0)