Skip to content

Commit 1629c8e

Browse files
committed
Sniffer: fix infinite loop stuck
1 parent 72170d8 commit 1629c8e

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

app/dispatcher/default.go

Lines changed: 12 additions & 4 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"
@@ -373,7 +374,14 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
373374
return nil, ctx.Err()
374375
default:
375376
cachingStartingTimeStamp := time.Now()
377+
payloadLen := payload.Len()
376378
cacheErr := cReader.Cache(payload, cacheDeadline)
379+
if cacheErr != nil {
380+
return nil, cacheErr
381+
}
382+
if payload.Len() == payloadLen {
383+
return nil, io.EOF
384+
}
377385
cachingTimeElapsed := time.Since(cachingStartingTimeStamp)
378386
cacheDeadline -= cachingTimeElapsed
379387

@@ -383,14 +391,14 @@ func sniffer(ctx context.Context, cReader *cachedReader, metadataOnly bool, netw
383391
case common.ErrNoClue: // No Clue: protocol not matches, and sniffer cannot determine whether there will be a match or not
384392
totalAttempt++
385393
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-
}
394+
totalAttempt++
389395
default:
390396
return result, err
391397
}
398+
} else {
399+
return nil, io.EOF
392400
}
393-
if totalAttempt >= 2 || cacheDeadline <= 0 {
401+
if totalAttempt >= 32 || cacheDeadline <= 0 {
394402
return nil, errSniffingTimeout
395403
}
396404
}

0 commit comments

Comments
 (0)