Skip to content

Commit

Permalink
cancel sequence on success
Browse files Browse the repository at this point in the history
Signed-off-by: denis-tingaikin <[email protected]>
  • Loading branch information
denis-tingaikin committed Dec 11, 2023
1 parent 6f06ada commit 23fc4f1
Showing 1 changed file with 13 additions and 1 deletion.
14 changes: 13 additions & 1 deletion pkg/networkservice/common/heal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"time"

"github.com/edwarnicke/genericsync"
"github.com/networkservicemesh/api/pkg/api/networkservice"
"google.golang.org/grpc"
"google.golang.org/protobuf/types/known/emptypb"
Expand All @@ -32,8 +33,13 @@ import (
"github.com/networkservicemesh/sdk/pkg/tools/postpone"
)

type contextAndCancel struct {
context.Context
cancel func()
}
type healClient struct {
chainCtx context.Context
contextMap genericsync.Map[string, contextAndCancel]
livenessCheck LivenessCheck
livenessCheckInterval time.Duration
livenessCheckTimeout time.Duration
Expand Down Expand Up @@ -70,7 +76,10 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ
conn, err := next.Client(ctx).Request(ctx, request, opts...)
if err != nil {
if len(request.GetConnection().GetPath().GetPathSegments()) > 1 && h.livenessCheck == nil && !loopHandle.healingStarted {
_ = begin.FromContext(ctx).Request(begin.WithReselect())
var healCtx, cancel = context.WithCancel(h.chainCtx)
var ctxAndCancel = contextAndCancel{Context: healCtx, cancel: cancel}
ctxAndCancel, _ = h.contextMap.LoadOrStore(request.GetConnection().GetId(), ctxAndCancel)
_ = begin.FromContext(ctx).Request(begin.WithReselect(), begin.CancelContext(ctxAndCancel.Context))
}
if loaded && !loopHandle.healingStarted {
eventLoopErr := h.startEventLoop(ctx, request.GetConnection())
Expand All @@ -90,6 +99,9 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ
_, _ = next.Client(closeCtx).Close(closeCtx, conn)
return nil, eventLoopErr
}
if v, ok := h.contextMap.LoadAndDelete(request.GetConnection().GetId()); ok {
v.cancel()
}
return conn, nil
}

Expand Down

0 comments on commit 23fc4f1

Please sign in to comment.