Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: wrap ctx.Err() with a stack #29318

Closed
wants to merge 1 commit into from

Conversation

jordanlewis
Copy link
Member

It's all to common to get an error like "context canceled" without any
helpful information about which context was canceled and when. This
commit strives to improve the situation by at least including the stack
trace of when the ctx.Err() was retrieved.

Not sure who to include on this. It's a straw-man PR, also.

Release note: None

@cockroach-teamcity
Copy link
Member

This change is Reviewable

Copy link
Contributor

@maddyblue maddyblue left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like the idea, but it looks like the search and replace you did needs some more finesse.

pkg/cmd/github-pull-request-make/testdata/27595.diff Outdated Show resolved Hide resolved
pkg/internal/client/txn.go Outdated Show resolved Hide resolved
pkg/internal/client/txn.go Outdated Show resolved Hide resolved
pkg/internal/client/txn.go Outdated Show resolved Hide resolved
pkg/server/problem_ranges.go Outdated Show resolved Hide resolved
@jordanlewis
Copy link
Member Author

Thanks for the review, lol, I'll go audit these more carefully now.

@jordanlewis jordanlewis force-pushed the wrap-ctx-err branch 5 times, most recently from f7bd5b2 to b2a6645 Compare August 30, 2018 02:15
@jordanlewis
Copy link
Member Author

RFAL

@petermattis
Copy link
Collaborator

Generating stack traces is fairly expensive. I'm not sure if that will be a problem here, just pointing it out. I'm a bit reluctant to have this always on. Perhaps the wrapping should be done in a way that it is controlled by an environment variable. Just brainstorming here. I haven't thought through this enough.

I'd guess that you'd rather get a stack trace from the goroutine that cancelled the context. I think that might be possible if we vendor context (I'm pretty sure you can vendor stdlib packages).

@jordanlewis
Copy link
Member Author

Would using the GetSmallTrace facility be sufficiently cheaper to help you get over your reluctance? The problem is that these errors are generally pesky and hard to track down. They come up in the wild, and when they do, you really want to see more context from the error.

For example, from @andreimatei:

btw, when I'm running TPCC on a 4-node roachprod cluster (2 or 3 workloads running at the same time), I see the client getting Error: error in newOrder: pq: context deadline exceeded pretty often. Don't know what's up with those :S

@petermattis
Copy link
Collaborator

Would using the GetSmallTrace facility be sufficiently cheaper to help you get over your reluctance? The problem is that these errors are generally pesky and hard to track down. They come up in the wild, and when they do, you really want to see more context from the error.

I haven't measured the perf difference between debug.Stack and GetSmallTrace. I'd be surprised if there is a significant difference, but it is worth looking at. Previous experience has shown that calling debug.Stack too frequently (e.g. in non error paths) is a significant perf hit. I realize this PR is only doing it in error paths, but I'm just being cautious.

It's all to common to get an error like "context canceled" without any
helpful information about which context was canceled and when. This
commit strives to improve the situation by at least including the stack
trace of when the ctx.Err() was retrieved.

Release note: None
Copy link
Contributor

@andreimatei andreimatei left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, the more important stack is the one of the routine doing the canceling than the canceled one. For the cancelee, I think a message identifying its location ("ctx canceled while waiting for foo") is sufficient, instead of the stack.

Btw, I hope you've searched the code for places that handle context.ErrCanceled explicitly. I know for example @vivekmenezes is just introducing one currently.

Reviewable status: :shipit: complete! 0 of 0 LGTMs obtained

@jordanlewis
Copy link
Member Author

This isn't as good as #29429.

@jordanlewis jordanlewis deleted the wrap-ctx-err branch May 22, 2019 18:19
craig bot pushed a commit that referenced this pull request Jun 16, 2019
29429: contextutil: add CancelWithReason r=jordanlewis a=jordanlewis

contextutil.WithCancel now returns a new context type that holds its
reason for cancellation when canceled with CancelWithReason instead of
its normal cancelfunc.

Alternative / new approach to #29318.

Release note: None

Co-authored-by: Jordan Lewis <jordanthelewis@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants