@@ -20,6 +20,7 @@ import (
2020 "context"
2121 "time"
2222
23+ "github.com/edwarnicke/genericsync"
2324 "github.com/networkservicemesh/api/pkg/api/networkservice"
2425 "google.golang.org/grpc"
2526 "google.golang.org/protobuf/types/known/emptypb"
@@ -32,8 +33,13 @@ import (
3233 "github.com/networkservicemesh/sdk/pkg/tools/postpone"
3334)
3435
36+ type contextAndCancel struct {
37+ context.Context
38+ cancel func ()
39+ }
3540type healClient struct {
3641 chainCtx context.Context
42+ contextMap genericsync.Map [string , contextAndCancel ]
3743 livenessCheck LivenessCheck
3844 livenessCheckInterval time.Duration
3945 livenessCheckTimeout time.Duration
@@ -70,7 +76,10 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ
7076 conn , err := next .Client (ctx ).Request (ctx , request , opts ... )
7177 if err != nil {
7278 if len (request .GetConnection ().GetPath ().GetPathSegments ()) > 1 && h .livenessCheck == nil && ! loopHandle .healingStarted {
73- _ = begin .FromContext (ctx ).Request (begin .WithReselect ())
79+ var healCtx , cancel = context .WithCancel (h .chainCtx )
80+ var ctxAndCancel = contextAndCancel {Context : healCtx , cancel : cancel }
81+ ctxAndCancel , _ = h .contextMap .LoadOrStore (request .GetConnection ().GetId (), ctxAndCancel )
82+ _ = begin .FromContext (ctx ).Request (begin .WithReselect (), begin .CancelContext (ctxAndCancel .Context ))
7483 }
7584 if loaded && ! loopHandle .healingStarted {
7685 eventLoopErr := h .startEventLoop (ctx , request .GetConnection ())
@@ -90,6 +99,9 @@ func (h *healClient) Request(ctx context.Context, request *networkservice.Networ
9099 _ , _ = next .Client (closeCtx ).Close (closeCtx , conn )
91100 return nil , eventLoopErr
92101 }
102+ if v , ok := h .contextMap .LoadAndDelete (request .GetConnection ().GetId ()); ok {
103+ v .cancel ()
104+ }
93105 return conn , nil
94106}
95107
0 commit comments