Skip to content

Commit

Permalink
[qfix] Fix deadlineCtx in eventloop (#1277)
Browse files Browse the repository at this point in the history
* fix deadlineCtx + rename livenessCheck func

Signed-off-by: Nikita Skrynnik <[email protected]>

* fix naming

Signed-off-by: Nikita Skrynnik <[email protected]>
  • Loading branch information
NikitaSkrynnik authored May 5, 2022
1 parent 5e4251a commit 8d67627
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 17 deletions.
16 changes: 8 additions & 8 deletions pkg/networkservice/common/heal/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ import (
)

type healClient struct {
chainCtx context.Context
dataPlaneLivenessCheck LivenessCheck
livenessCheckInterval time.Duration
livenessCheckTimeout time.Duration
chainCtx context.Context
livenessCheck LivenessCheck
livenessCheckInterval time.Duration
livenessCheckTimeout time.Duration
}

// NewClient - returns a new heal client chain element
Expand All @@ -48,10 +48,10 @@ func NewClient(chainCtx context.Context, opts ...Option) networkservice.NetworkS
opt(o)
}
return &healClient{
chainCtx: chainCtx,
dataPlaneLivenessCheck: o.dataPlaneLivenessCheck,
livenessCheckInterval: o.livenessCheckInterval,
livenessCheckTimeout: o.livenessCheckTimeout,
chainCtx: chainCtx,
livenessCheck: o.livenessCheck,
livenessCheckInterval: o.livenessCheckInterval,
livenessCheckTimeout: o.livenessCheckTimeout,
}
}

Expand Down
8 changes: 3 additions & 5 deletions pkg/networkservice/common/heal/eventloop.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ func (cev *eventLoop) eventLoop() {

livenessCheckCtx, livenessCheckCancel := context.WithCancel(context.Background())
defer livenessCheckCancel()
if cev.heal.dataPlaneLivenessCheck != nil {
if cev.heal.livenessCheck != nil {
go func() {
cev.monitorDataPlane()
livenessCheckCancel()
Expand Down Expand Up @@ -193,15 +193,13 @@ func (cev *eventLoop) monitorDataPlane() {
for {
select {
case <-ticker.C:
deadlineCtx, deadlineCancel := context.WithDeadline(context.Background(), time.Now().Add(cev.heal.livenessCheckTimeout))
alive := cev.heal.dataPlaneLivenessCheck(deadlineCtx, cev.conn)
deadlineCtx, deadlineCancel := context.WithDeadline(cev.chainCtx, time.Now().Add(cev.heal.livenessCheckTimeout))
alive := cev.heal.livenessCheck(deadlineCtx, cev.conn)
deadlineCancel()

if !alive {
return
}
case <-cev.chainCtx.Done():
return
case <-cev.eventLoopCtx.Done():
return
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/networkservice/common/heal/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ const (
type LivenessCheck func(deadlineCtx context.Context, conn *networkservice.Connection) bool

type options struct {
dataPlaneLivenessCheck LivenessCheck
livenessCheckInterval time.Duration
livenessCheckTimeout time.Duration
livenessCheck LivenessCheck
livenessCheckInterval time.Duration
livenessCheckTimeout time.Duration
}

// Option - option for heal.NewClient() chain element
Expand All @@ -43,7 +43,7 @@ type Option func(o *options)
// WithLivenessCheck - sets the data plane liveness checker
func WithLivenessCheck(livenessCheck LivenessCheck) Option {
return func(o *options) {
o.dataPlaneLivenessCheck = livenessCheck
o.livenessCheck = livenessCheck
}
}

Expand Down

0 comments on commit 8d67627

Please sign in to comment.