Skip to content

Commit

Permalink
update context errors handling
Browse files Browse the repository at this point in the history
Signed-off-by: Ruslan Bayandinov <wazsone@ya.ru>
  • Loading branch information
wazsone committed Feb 2, 2023
1 parent b6301b4 commit ea1b01f
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ func NewMonitorConnectionMonitorConnectionsClient(ctx context.Context, eventCh <
func (m *monitorConnectionMonitorConnectionsClient) Recv() (*networkservice.ConnectionEvent, error) {
select {
case <-m.ctx.Done():
return nil, errors.WithStack(m.ctx.Err())
return nil, errors.Wrap(m.ctx.Err(), "application context is done")
case event, ok := <-m.eventCh:
if !ok {
m.cancelFunc()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func NewMonitorConnectionMonitorConnectionsServer(ctx context.Context, eventCh c
func (m *monitorConnectionMonitorConnectionsServer) Send(event *networkservice.ConnectionEvent) error {
select {
case <-m.ctx.Done():
return errors.WithStack(m.ctx.Err())
return errors.Wrap(m.ctx.Err(), "application context is done")
case m.eventCh <- event:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/networkservice/utils/checks/checkconnection/client.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2020-2023 Cisco and/or its affiliates.
// Copyright (c) 2020-2022 Cisco and/or its affiliates.
//
// SPDX-License-Identifier: Apache-2.0
//
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/common/memory/ns_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ func (s *memoryNSServer) Find(query *registry.NetworkServiceQuery, server regist
var err error
for ; err == nil; err = s.receiveEvent(query, server, eventCh) {
}
if err.Error() != io.EOF.Error() {
if errors.Cause(err).Error() != io.EOF.Error() {
return err
}
return next.NetworkServiceRegistryServer(server.Context()).Find(query, server)
Expand Down Expand Up @@ -146,7 +146,7 @@ func (s *memoryNSServer) receiveEvent(
) error {
select {
case <-server.Context().Done():
return errors.WithStack(io.EOF)
return errors.Wrap(io.EOF, "find context is done")
case event := <-eventCh:
if matchutils.MatchNetworkServices(query.NetworkService, event) {
nse := &registry.NetworkServiceResponse{
Expand All @@ -155,7 +155,7 @@ func (s *memoryNSServer) receiveEvent(

if err := server.Send(nse); err != nil {
if server.Context().Err() != nil {
return errors.WithStack(io.EOF)
return errors.Wrapf(io.EOF, "find context has a error %s", server.Context().Err().Error())
}
return errors.Wrapf(err, "NetworkServiceRegistry find server failed to send a response %s", nse.String())
}
Expand Down
6 changes: 3 additions & 3 deletions pkg/registry/common/memory/nse_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func (s *memoryNSEServer) Find(query *registry.NetworkServiceEndpointQuery, serv
var err error
for ; err == nil; err = s.receiveEvent(query, server, eventCh) {
}
if err.Error() != io.EOF.Error() {
if errors.Cause(err).Error() != io.EOF.Error() {
return err
}
return nil
Expand Down Expand Up @@ -149,12 +149,12 @@ func (s *memoryNSEServer) receiveEvent(
) error {
select {
case <-server.Context().Done():
return errors.WithStack(io.EOF)
return errors.Wrap(io.EOF, "find context is done")
case event := <-eventCh:
if matchutils.MatchNetworkServiceEndpoints(query.NetworkServiceEndpoint, event.NetworkServiceEndpoint) {
if err := server.Send(event); err != nil {
if server.Context().Err() != nil {
return errors.WithStack(io.EOF)
return errors.Wrapf(io.EOF, "find context has a error %s", server.Context().Err().Error())
}
return errors.Wrapf(err, "NetworkServiceRegistry find server failed to send a response %s", event.String())
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/registry/common/recvfd/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func recvFDAndSwapInodeToUnix(ctx context.Context, fileMap *perEndpointFileMap,
// Wait for the file to arrive on the fileCh or the context to expire
select {
case <-ctx.Done():
err = errors.WithStack(ctx.Err())
err = errors.Wrap(ctx.Err(), "recvFDAndSwapInodeToUnix context is done")
return
case file = <-fileCh:
// If we get the file, remember it in the fileMap so we can reuse it later
Expand Down
20 changes: 10 additions & 10 deletions pkg/registry/common/retry/ns_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (r *retryNSClient) Register(ctx context.Context, in *registry.NetworkServic

select {
case <-r.chainCtx.Done():
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context is done")
case <-ctx.Done():
return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "register context is done")
case <-c.After(r.interval):
continue
}
Expand All @@ -80,10 +80,10 @@ func (r *retryNSClient) Register(ctx context.Context, in *registry.NetworkServic
}

if r.chainCtx.Err() != nil {
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context has an error")
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "register context has an error")
}

func (r *retryNSClient) Find(ctx context.Context, query *registry.NetworkServiceQuery, opts ...grpc.CallOption) (registry.NetworkServiceRegistry_FindClient, error) {
Expand All @@ -103,10 +103,10 @@ func (r *retryNSClient) Find(ctx context.Context, query *registry.NetworkService
}

if r.chainCtx.Err() != nil {
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context has an error")
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "find context has an error")
}

func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkService, opts ...grpc.CallOption) (*emptypb.Empty, error) {
Expand All @@ -123,9 +123,9 @@ func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkServ

select {
case <-r.chainCtx.Done():
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context is done")
case <-ctx.Done():
return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "unregister context is done")
case <-c.After(r.interval):
continue
}
Expand All @@ -134,8 +134,8 @@ func (r *retryNSClient) Unregister(ctx context.Context, in *registry.NetworkServ
return resp, err
}
if r.chainCtx.Err() != nil {
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context has an error")
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "unregister context has an error")
}
16 changes: 8 additions & 8 deletions pkg/registry/common/retry/nse_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,9 @@ func (r *retryNSEClient) Register(ctx context.Context, nse *registry.NetworkServ

select {
case <-r.chainCtx.Done():
return nil, err
return nil, errors.Wrap(r.chainCtx.Err(), "application context is done")
case <-ctx.Done():
return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "register context is done")
case <-c.After(r.interval):
continue
}
Expand All @@ -79,7 +79,7 @@ func (r *retryNSEClient) Register(ctx context.Context, nse *registry.NetworkServ
return resp, err
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "register context has an error")
}

func (r *retryNSEClient) Find(ctx context.Context, query *registry.NetworkServiceEndpointQuery, opts ...grpc.CallOption) (registry.NetworkServiceEndpointRegistry_FindClient, error) {
Expand All @@ -103,10 +103,10 @@ func (r *retryNSEClient) Find(ctx context.Context, query *registry.NetworkServic
}

if r.chainCtx.Err() != nil {
return nil, errors.WithStack(r.chainCtx.Err())
return nil, errors.Wrap(r.chainCtx.Err(), "application context has an error")
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "find context has an error")
}

func (r *retryNSEClient) Unregister(ctx context.Context, in *registry.NetworkServiceEndpoint, opts ...grpc.CallOption) (*emptypb.Empty, error) {
Expand All @@ -123,9 +123,9 @@ func (r *retryNSEClient) Unregister(ctx context.Context, in *registry.NetworkSer

select {
case <-r.chainCtx.Done():
return nil, err
return nil, errors.Wrap(r.chainCtx.Err(), "application context is done")
case <-ctx.Done():
return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "unregister context is done")
case <-c.After(r.interval):
continue
}
Expand All @@ -134,5 +134,5 @@ func (r *retryNSEClient) Unregister(ctx context.Context, in *registry.NetworkSer
return resp, err
}

return nil, errors.WithStack(ctx.Err())
return nil, errors.Wrap(ctx.Err(), "unregister context has an error")
}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ type networkServiceRegistryFindServer struct {
func (s *networkServiceRegistryFindServer) Send(nsResp *registry.NetworkServiceResponse) error {
select {
case <-s.ctx.Done():
return errors.WithStack(s.ctx.Err())
return errors.Wrap(s.ctx.Err(), "application context is done")
case s.sendCh <- nsResp:
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ type networkServiceEndpointRegistryFindServer struct {
func (s *networkServiceEndpointRegistryFindServer) Send(nseResp *registry.NetworkServiceEndpointResponse) error {
select {
case <-s.ctx.Done():
return errors.WithStack(s.ctx.Err())
return errors.Wrap(s.ctx.Err(), "application context is done")
case s.sendCh <- nseResp:
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/tools/spire/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ func execHealthCheck(ctx context.Context, cmdStr string, options ...*exechelper.
for {
select {
case <-ctx.Done():
return errors.WithStack(ctx.Err())
return errors.Wrap(ctx.Err(), "health check context is done")
default:
if err := exechelper.Run(cmdStr, options...); err == nil {
return nil
Expand Down

0 comments on commit ea1b01f

Please sign in to comment.