Skip to content

Commit

Permalink
Merge pull request #394 from acnodal/clean-timeouts
Browse files Browse the repository at this point in the history
Handle NS and NSE server wait timeouts cleanly
  • Loading branch information
denis-tingaikin authored Nov 15, 2022
2 parents e145a0b + d9b5a3c commit 08c7453
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 08c7453

Please sign in to comment.