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. In this case the Error has an "unknown" code so we
use the error message. When it happens we return nil and the
server-side streaming call is closed cleanly.

Signed-off-by: Toby Cabot <[email protected]>
  • Loading branch information
caboteria committed Oct 13, 2022
1 parent 4419e8d commit aa2212c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
8 changes: 7 additions & 1 deletion pkg/registry/etcd/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,13 @@ func (n *etcdNSRegistryServer) Find(query *registry.NetworkServiceQuery, s regis
}
}
if query.Watch {
if err := n.watch(query, s); err != nil && !errors.Is(err, io.EOF) {
if err := n.watch(query, s); err != nil {
// If we have timed out then return nil to close the stream
// cleanly
if errors.Is(err, io.EOF) || err.Error() == "context canceled" {
logger.Debug("watch timed out, closing stream")
return nil
}
return err
}
}
Expand Down
8 changes: 7 additions & 1 deletion pkg/registry/etcd/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,13 @@ func (n *etcdNSERegistryServer) Find(query *registry.NetworkServiceEndpointQuery
}
}
if query.Watch {
if err := n.watch(query, s); err != nil && !errors.Is(err, io.EOF) {
if err := n.watch(query, s); err != nil {
// If we have timed out then return nil to close the stream
// cleanly
if errors.Is(err, io.EOF) || err.Error() == "context canceled" {
logger.Debug("watch timed out, closing stream")
return nil
}
return err
}
}
Expand Down

0 comments on commit aa2212c

Please sign in to comment.