ydb-go-sdk
ydb-go-sdk copied to clipboard
Fix unreadable context error in ydb.Open
When ydb.Open is called with an already-expired context, the error message chains multiple stack traces, making it difficult to diagnose:
retry failed on attempt No.1: context deadline exceeded at `retry.RetryWithResult(retry.go:337)` at `retry.Retry(retry.go:270)` at `balancer.New(balancer.go:322)` at `(*Driver).connect(driver.go:458)` at `Open(driver.go:314)`
Changes
- retry/retry.go: Check for expired context before entering retry loop; avoid wrapping context errors with stack traces
- internal/balancer/balancer.go: Propagate context errors without stack trace wrapping
- driver.go: Propagate context errors without stack trace wrapping
Context errors now show a single, meaningful stack trace at the Open() level:
context deadline exceeded at `github.com/ydb-platform/ydb-go-sdk/v3.Open(driver.go:314)`
The early context check in retry logic also prevents misleading "retry failed on attempt No.1" messages when no actual retry attempt was made.
[!WARNING]
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
invalid_hostIf you need me to access, download, or install something from one of these locations, you can either:
- Configure Actions setup steps to set up my environment, which run before the firewall is enabled
- Add the appropriate URLs or hosts to the custom allowlist in this repository's Copilot coding agent settings (admins only)
Original prompt
This section details on the original issue you should resolve
<issue_title>bug: Unreadable error when context deadline is exceeded in
ydb.Open</issue_title> <issue_description># Bug ReportYDB GO SDK version:
v3.118.0Environment
All environments
Current behavior:
When the context passed to ydb.Open has its deadline exceeded, an error message is displayed that is difficult to understand. This makes it challenging to diagnose and resolve the issue.
Expected behavior:
Error something like:
context deadline exceeded at Open(driver.go:XXX)Steps to reproduce:
- Create a context with a deadline that has already been exceeded.
- Pass this context to the ydb.Open function.
- Observe the error message that is returned.
func TestOpen(t *testing.T) { ctx, cancel := context.WithTimeout(context.Background(), 1*time.Nanosecond) defer cancel() time.Sleep(10 * time.Nanosecond) _, err := ydb.Open(ctx, "grpc://localhost:2136/local") require.NoError(t, err) }Error: Received unexpected error: retry failed on attempt No.1: context deadline exceeded at `github.com/ydb-platform/ydb-go-sdk/v3/retry.RetryWithResult(retry.go:337)` at `github.com/ydb-platform/ydb-go-sdk/v3/retry.Retry(retry.go:270)` at `github.com/ydb-platform/ydb-go-sdk/v3/internal/balancer.New(balancer.go:322)` at `github.com/ydb-platform/ydb-go-sdk/v3.(*Driver).connect(driver.go:458)` at `github.com/ydb-platform/ydb-go-sdk/v3.Open(driver.go:314)` ```</issue_description> ## Comments on the Issue (you are @copilot in this section) <comments> </comments>
- Fixes ydb-platform/ydb-go-sdk#1926
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.