Skip to content

Commit

Permalink
only prefetch if necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
WeidiDeng committed Jun 28, 2024
1 parent 1349d38 commit 36cd8fe
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions layer4/routes.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,19 @@ func (routes RouteList) Compile(logger *zap.Logger, matchingTimeout time.Duratio
return err
}
for {
err = cx.prefetch()
if err != nil {
logFunc := logger.Error
if errors.Is(err, os.ErrDeadlineExceeded) {
err = ErrMatchingTimeout
logFunc = logger.Warn
// only prefetch is needed, it's useful in case a RouteList in another RouteList cases
// if some matchers returned ErrConsumedAllPrefetchedBytes, it's true anyway
if len(cx.buf) == 0 || len(cx.buf) == cx.offset {
err = cx.prefetch()
if err != nil {
logFunc := logger.Error
if errors.Is(err, os.ErrDeadlineExceeded) {
err = ErrMatchingTimeout
logFunc = logger.Warn
}
logFunc("matching connection", zap.String("remote", cx.RemoteAddr().String()), zap.Error(err))
return nil // return nil so the error does not get logged again
}
logFunc("matching connection", zap.String("remote", cx.RemoteAddr().String()), zap.Error(err))
return nil // return nil so the error does not get logged again
}

for i, route := range routes {
Expand Down

0 comments on commit 36cd8fe

Please sign in to comment.