Skip to content

Commit

Permalink
Fix review comments
Browse files Browse the repository at this point in the history
Signed-off-by: Artem Glazychev <[email protected]>
  • Loading branch information
glazychev-art committed Apr 11, 2023
1 parent f0a3af6 commit 37fd011
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions pkg/networkservice/common/timeout/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (s *timeoutServer) Request(ctx context.Context, request *networkservice.Net
}
store(ctx, metadata.IsClient(s), cancel)
eventFactory := begin.FromContext(ctx)
afterCh := timeClock.After(after(ctx, conn) - requestTimeout)
afterCh := timeClock.After(minTokenTimeout(ctx, conn) - requestTimeout)

go func(cancelCtx context.Context, afterCh <-chan time.Time) {
select {
Expand All @@ -93,33 +93,20 @@ func (s *timeoutServer) Close(ctx context.Context, conn *networkservice.Connecti
return &empty.Empty{}, err
}

func after(ctx context.Context, conn *networkservice.Connection) time.Duration {
func minTokenTimeout(ctx context.Context, conn *networkservice.Connection) time.Duration {
clockTime := clock.FromContext(ctx)

var minTimeout *time.Duration
var expireTime time.Time
var minTimeout time.Duration = 0
for _, segment := range conn.GetPath().GetPathSegments() {
if segment.GetExpires() == nil {
continue
}
expTime := segment.GetExpires().AsTime()

timeout := clockTime.Until(expTime)

if minTimeout == nil || timeout < *minTimeout {
if minTimeout == nil {
minTimeout = new(time.Duration)
}
timeout := clockTime.Until(segment.GetExpires().AsTime())

*minTimeout = timeout
expireTime = expTime
if timeout < minTimeout || minTimeout == 0 {
minTimeout = timeout
}
}
log.FromContext(ctx).Infof("expiration after %s", minTimeout.String())

if minTimeout == nil || *minTimeout <= 0 {
return 1
}
log.FromContext(ctx).Infof("expiration after %s at %s", minTimeout.String(), expireTime.UTC())

return *minTimeout
return minTimeout
}

0 comments on commit 37fd011

Please sign in to comment.