Skip to content

Commit

Permalink
Fix using context for logout.
Browse files Browse the repository at this point in the history
  • Loading branch information
Denis Krivak committed Sep 9, 2023
1 parent 9c4baaf commit 5bcfbd6
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion collector.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ func (c *Collector) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
defer func() {
if err := client.Logout(r.Context()); err != nil {
// Use a separate context to avoid cancelling logout when
// the request is cancelled
ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second)
defer cancel()
if err := client.Logout(ctx); err != nil {
log.Fatalf("Failed to logout: %v", err)
}
}()
Expand Down

0 comments on commit 5bcfbd6

Please sign in to comment.