Skip to content

Commit

Permalink
fix data race in heal server
Browse files Browse the repository at this point in the history
Signed-off-by: Danil Uzlov <DanilUzlov@yandex.ru>
  • Loading branch information
d-uzlov committed Apr 23, 2021
1 parent 5c10e50 commit 26410c2
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions pkg/networkservice/common/heal/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ func (f *healServer) Request(ctx context.Context, request *networkservice.Networ
}

cw, loaded := f.healContextMap.LoadOrStore(request.GetConnection().GetId(), &ctxWrapper{
request: request.Clone().SetRequestConnection(conn.Clone()),
request: request.Clone(),
ctx: f.createHealContext(ctx, nil),
})
if loaded {
Expand All @@ -94,7 +94,7 @@ func (f *healServer) Request(ctx context.Context, request *networkservice.Networ
cw.cancel()
cw.cancel = nil
}
cw.request = request.Clone().SetRequestConnection(conn.Clone())
cw.request = request.Clone()
cw.ctx = f.createHealContext(ctx, cw.ctx)
}

Expand All @@ -112,9 +112,6 @@ func (f *healServer) Close(ctx context.Context, conn *networkservice.Connection)
}

func (f *healServer) getHealContext(conn *networkservice.Connection) (*networkservice.NetworkServiceRequest, context.Context) {
var healCtx context.Context
var request *networkservice.NetworkServiceRequest

cw, ok := f.healContextMap.Load(conn.GetId())
if !ok {
return nil, nil
Expand All @@ -128,10 +125,9 @@ func (f *healServer) getHealContext(conn *networkservice.Connection) (*networkse
}
ctx, cancel := context.WithCancel(cw.ctx)
cw.cancel = cancel
healCtx = ctx
request = cw.request
request := cw.request.Clone()

return request, healCtx
return request, ctx
}

// handleHealConnectionRequest - heals requested connection. Returns immediately, heal is asynchronous.
Expand Down

0 comments on commit 26410c2

Please sign in to comment.