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

release-22.1: Revert "sql: improve stack trace for get-user-timeout timeouts" #96474

Merged
merged 1 commit into from
Feb 3, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 0 additions & 13 deletions pkg/util/contextutil/context.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,26 +79,13 @@ func wrap(ctx context.Context, cancel context.CancelFunc) (context.Context, cont
}
}

// ctxWithStacktrace overrides Err to annotate context.DeadlineExceeded and
// context.Canceled errors with a stacktrace.
// See: https://github.com/cockroachdb/cockroach/issues/95794
type ctxWithStacktrace struct {
context.Context
}

// Err implements the context.Context interface.
func (ctx *ctxWithStacktrace) Err() error {
return errors.WithStack(ctx.Context.Err())
}

// RunWithTimeout runs a function with a timeout, the same way you'd do with
// context.WithTimeout. It improves the opaque error messages returned by
// WithTimeout by augmenting them with the op string that is passed in.
func RunWithTimeout(
ctx context.Context, op string, timeout time.Duration, fn func(ctx context.Context) error,
) error {
ctx, cancel := context.WithTimeout(ctx, timeout)
ctx = &ctxWithStacktrace{Context: ctx}
defer cancel()
start := timeutil.Now()
err := fn(ctx)
Expand Down
19 changes: 0 additions & 19 deletions pkg/util/contextutil/context_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ package contextutil

import (
"context"
"fmt"
"net"
"testing"
"time"
Expand Down Expand Up @@ -69,24 +68,6 @@ func TestRunWithTimeout(t *testing.T) {
}
}

func testFuncA(ctx context.Context) error {
return testFuncB(ctx)
}

func testFuncB(ctx context.Context) error {
<-ctx.Done()
return ctx.Err()
}

func TestRunWithTimeoutCtxWithStacktrace(t *testing.T) {
ctx := context.Background()
err := RunWithTimeout(ctx, "foo", 1, testFuncA)
require.Error(t, err)
stacktrace := fmt.Sprintf("%+v", err)
require.Contains(t, stacktrace, "testFuncB")
require.Contains(t, stacktrace, "testFuncA")
}

// TestRunWithTimeoutWithoutDeadlineExceeded ensures that when a timeout on the
// context occurs but the underlying error does not have
// context.DeadlineExceeded as its Cause (perhaps due to serialization) the
Expand Down