Skip to content

Commit

Permalink
Revert "sql: improve stack trace for get-user-timeout timeouts"
Browse files Browse the repository at this point in the history
This reverts commit 662e19c.

gRPC does note expect the context to be wrapped, so it can get confused.

Release note: None
  • Loading branch information
rafiss committed Feb 3, 2023
1 parent ca70b82 commit 7c42e35
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 32 deletions.
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 @@ -71,24 +70,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

0 comments on commit 7c42e35

Please sign in to comment.