Skip to content

Commit

Permalink
Cherry-pick v20.07: fix(worker): Cancel the context when opening conn…
Browse files Browse the repository at this point in the history
…ection to leader for streaming snapshot (#6045)

Co-authored-by: Manish R Jain <manish@dgraph.io>
  • Loading branch information
parasssh and manishrjain authored Jul 20, 2020
1 parent d6c58a7 commit c191850
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion worker/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@ func (n *node) populateSnapshot(snap pb.Snapshot, pl *conn.Pool) (int, error) {
con := pl.Get()
c := pb.NewWorkerClient(con)

// We should absolutely cancel the context when we return from this function, that way, the
// leader who is sending the snapshot would stop sending.
ctx, cancel := context.WithCancel(n.ctx)
defer cancel()

// Set my RaftContext on the snapshot, so it's easier to locate me.
ctx := n.ctx
snap.Context = n.RaftContext
stream, err := c.StreamSnapshot(ctx)
if err != nil {
Expand Down

0 comments on commit c191850

Please sign in to comment.