Skip to content

Commit

Permalink
Prevent cancel propagation into replaceFn
Browse files Browse the repository at this point in the history
Cancel propagation is usually unintended for request coalescing, which represents *multiple* HTTP requests or similar.
  • Loading branch information
motoki317 committed Mar 25, 2024
1 parent f680c50 commit c24560d
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,9 @@ retry:
c.calls[key] = cl
c.mu.Unlock()

c.set(ctx, cl, key) // make sure not to hold lock while waiting for value
// Make sure not to hold lock while waiting for value.
// Use context.WithoutCancel to match the behavior with background fetching.
c.set(context.WithoutCancel(ctx), cl, key)
return cl.val.v, cl.err
}

Expand Down

0 comments on commit c24560d

Please sign in to comment.