Skip to content

Commit

Permalink
debug context
Browse files Browse the repository at this point in the history
  • Loading branch information
pcfreak30 committed Jan 8, 2025
1 parent 8861db8 commit e5eb35e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions internal/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,18 @@ func (c *TracedContext) Cleanup() {
func NewCancelContext(parent context.Context) (context.Context, context.CancelFunc) {
ctx, cancel := context.WithCancel(parent)

return ctx, func() {
fmt.Printf("Cancel called for context from:\n%s\n", string(debug.Stack()))
cancel()
wrappedCancel := func() {
// Only print stack trace if we're not already cancelled
select {
case <-ctx.Done():
// Context is already cancelled, just propagate the cancellation
cancel()
default:
// This is a new cancellation, print the stack trace
fmt.Printf("Cancel called for context from:\n%s\n", string(debug.Stack()))
cancel()
}
}

return ctx, wrappedCancel
}

0 comments on commit e5eb35e

Please sign in to comment.