mirror of https://github.com/status-im/consul.git
resource: handle `ErrWatchClosed` in `WatchList` endpoint (#17289)
This commit is contained in:
parent
879b775459
commit
0a38fc1a2a
|
@ -4,6 +4,8 @@
|
||||||
package resource
|
package resource
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
|
|
||||||
"google.golang.org/grpc/codes"
|
"google.golang.org/grpc/codes"
|
||||||
"google.golang.org/grpc/status"
|
"google.golang.org/grpc/status"
|
||||||
|
|
||||||
|
@ -51,7 +53,10 @@ func (s *Server) WatchList(req *pbresource.WatchListRequest, stream pbresource.R
|
||||||
|
|
||||||
for {
|
for {
|
||||||
event, err := watch.Next(stream.Context())
|
event, err := watch.Next(stream.Context())
|
||||||
if err != nil {
|
switch {
|
||||||
|
case errors.Is(err, storage.ErrWatchClosed):
|
||||||
|
return status.Error(codes.Aborted, "watch closed by the storage backend (possibly due to snapshot restoration)")
|
||||||
|
case err != nil:
|
||||||
return status.Errorf(codes.Internal, "failed next: %v", err)
|
return status.Errorf(codes.Internal, "failed next: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue