Skip to content

Commit

Permalink
Handle NS and NSE server wait timeouts cleanly
Browse files Browse the repository at this point in the history
gRPC server-side streaming calls should be closed by returning nil so
we need to figure out what the timeout Error looks like and return nil
when it happens so we don't get logs full of spurious errors.

Signed-off-by: Toby Cabot <[email protected]>
  • Loading branch information
caboteria committed Nov 8, 2022
1 parent 4419e8d commit d9b5a3c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ func (n *etcdNSRegistryServer) Register(ctx context.Context, request *registry.N
}

func (n *etcdNSRegistryServer) watch(query *registry.NetworkServiceQuery, s registry.NetworkServiceRegistry_FindServer) error {
logger := log.FromContext(n.chainContext).WithField("etcdNSRegistryServer", "watch")
var watchErr error
for watchErr == nil {
timeoutSeconds := int64(time.Minute / time.Second)
Expand All @@ -108,6 +109,14 @@ func (n *etcdNSRegistryServer) watch(query *registry.NetworkServiceQuery, s regi

watcher.Stop()
}

// If the watch timed out, return nil to close the stream
// cleanly.
if errors.Is(watchErr, context.Canceled) {
logger.Debug("watch timed out, returning nil")
return nil
}
// If something else went wrong, return the error.
return watchErr
}

Expand Down
9 changes: 9 additions & 0 deletions pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ func (n *etcdNSERegistryServer) Unregister(ctx context.Context, request *registr
}

func (n *etcdNSERegistryServer) watch(query *registry.NetworkServiceEndpointQuery, s registry.NetworkServiceEndpointRegistry_FindServer) error {
logger := log.FromContext(n.chainContext).WithField("etcdNSERegistryServer", "watch")
var watchErr error
for watchErr == nil {
timeoutSeconds := int64(time.Minute / time.Second)
Expand All @@ -158,6 +159,14 @@ func (n *etcdNSERegistryServer) watch(query *registry.NetworkServiceEndpointQuer

watcher.Stop()
}

// If the watch timed out, return nil to close the stream
// cleanly.
if errors.Is(watchErr, context.Canceled) {
logger.Debug("watch timed out, returning nil")
return nil
}
// If something else went wrong, return the error.
return watchErr
}

Expand Down

0 comments on commit d9b5a3c

Please sign in to comment.