Skip to content

Commit

Permalink
Cancel context before replacing it
Browse files Browse the repository at this point in the history
  • Loading branch information
belimawr committed Sep 16, 2024
1 parent 8794c22 commit f2718c3
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions libbeat/esleg/eslegclient/connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,10 @@ func (conn *Connection) Connect() error {
conn.log = logp.NewLogger("esclientleg")
}

// Cancel the old context before replacing it. Because this Connection
// is not goroutine safe, there should be no in-flight request using
// this context, hence it's safe to cancel it.
conn.cancelReqs()
conn.reqsContext, conn.cancelReqs = context.WithCancel(context.Background())

if err := conn.getVersion(); err != nil {
Expand Down

0 comments on commit f2718c3

Please sign in to comment.