I have the following function: func (s *SimplePeerConn) Read(b []byte) (n int, err error) { ctx := context.Background() var maybeCancelFn context.CancelFunc func() { s.deadlineLock.RLock() defer s.deadlineLock.RUnlock() if !s.readDeadline.IsZero() { ctx, maybeCancelFn = context.WithDeadline(ctx, s.readDeadline) } }() if maybeCancelFn != nil { defer maybeCancelFn() } return s.ReadWithContext(ctx, b) }
And I'm getting a possible context leak when I assign maybeCancelFn. I originally had context.WithCancel and then overwrote the cancelFn in the inner func. How would I idiomatically rewrite this to not see the vet error? -- You received this message because you are subscribed to the Google Groups "golang-nuts" group. To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.