Skip to content

Commit 49723a6

Browse files
authored
Merge pull request #728 from ydb-platform/context
`xcontext.With{Cancel,Timeout}` with stack trace record
2 parents 055e78b + dba7557 commit 49723a6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+22789
-341
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
* Implemented `xcontext.With{Cancel,Timeout}` with stack record and switched all usages from standard `context.With{Cancel,Timeout}`
2+
13
## v3.46.0
24
* Refactored package `log` for support typed fields in log messages
35

connection.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ type Connection interface {
8181
Topic() topic.Client
8282
}
8383

84+
var _ Connection = (*Driver)(nil)
85+
8486
// Driver type provide access to YDB service clients
8587
type Driver struct { //nolint:maligned
8688
userInfo *dsn.UserInfo

connection_test.go

Lines changed: 0 additions & 61 deletions
This file was deleted.

integration-insecure.txt

Lines changed: 11094 additions & 0 deletions
Large diffs are not rendered by default.

integration-secure.txt

Lines changed: 11093 additions & 0 deletions
Large diffs are not rendered by default.

internal/background/worker.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,15 @@ type Worker struct {
3030
tasks chan backgroundTask
3131

3232
closed bool
33-
stop xcontext.CancelErrFunc
33+
stop context.CancelFunc
3434
closeReason error
3535
}
3636

3737
type CallbackFunc func(ctx context.Context)
3838

3939
func NewWorker(parent context.Context) *Worker {
4040
w := Worker{}
41-
w.ctx, w.stop = xcontext.WithErrCancel(parent)
41+
w.ctx, w.stop = xcontext.WithCancel(parent)
4242

4343
return &w
4444
}
@@ -88,7 +88,7 @@ func (b *Worker) Close(ctx context.Context, err error) error {
8888
b.closeReason = errClosedWithNilReason
8989
}
9090

91-
b.stop(err)
91+
b.stop()
9292
})
9393
if resErr != nil {
9494
return resErr
@@ -121,7 +121,7 @@ func (b *Worker) CloseReason() error {
121121
func (b *Worker) init() {
122122
b.onceInit.Do(func() {
123123
if b.ctx == nil {
124-
b.ctx, b.stop = xcontext.WithErrCancel(context.Background())
124+
b.ctx, b.stop = xcontext.WithCancel(context.Background())
125125
}
126126
b.tasks = make(chan backgroundTask)
127127
b.tasksCompleted = make(empty.Chan)

internal/balancer/balancer.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
discoveryConfig "github.com/ydb-platform/ydb-go-sdk/v3/internal/discovery/config"
1616
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
1717
"github.com/ydb-platform/ydb-go-sdk/v3/internal/repeater"
18+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1819
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1920
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xsync"
2021
"github.com/ydb-platform/ydb-go-sdk/v3/retry"
@@ -94,9 +95,9 @@ func (b *Balancer) clusterDiscoveryAttempt(ctx context.Context) (err error) {
9495
}()
9596

9697
if dialTimeout := b.driverConfig.DialTimeout(); dialTimeout > 0 {
97-
ctx, cancel = context.WithTimeout(ctx, dialTimeout)
98+
ctx, cancel = xcontext.WithTimeout(ctx, dialTimeout)
9899
} else {
99-
ctx, cancel = context.WithCancel(ctx)
100+
ctx, cancel = xcontext.WithCancel(ctx)
100101
}
101102
defer cancel()
102103

internal/balancer/local_dc.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"sync"
1212

1313
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
14+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1415
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
1516
)
1617

@@ -19,7 +20,7 @@ const (
1920
)
2021

2122
func checkFastestAddress(ctx context.Context, addresses []string) string {
22-
ctx, cancel := context.WithCancel(ctx)
23+
ctx, cancel := xcontext.WithCancel(ctx)
2324
defer cancel()
2425

2526
type result struct {

internal/cmd/gtrace/gtrace

9.14 MB
Binary file not shown.

internal/conn/conn.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
"github.com/ydb-platform/ydb-go-sdk/v3/internal/endpoint"
1717
"github.com/ydb-platform/ydb-go-sdk/v3/internal/meta"
1818
"github.com/ydb-platform/ydb-go-sdk/v3/internal/response"
19+
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xcontext"
1920
"github.com/ydb-platform/ydb-go-sdk/v3/internal/xerrors"
2021
"github.com/ydb-platform/ydb-go-sdk/v3/trace"
2122
)
@@ -180,7 +181,7 @@ func (c *conn) realConn(ctx context.Context) (cc *grpc.ClientConn, err error) {
180181

181182
if dialTimeout := c.config.DialTimeout(); dialTimeout > 0 {
182183
var cancel context.CancelFunc
183-
ctx, cancel = context.WithTimeout(ctx, dialTimeout)
184+
ctx, cancel = xcontext.WithTimeout(ctx, dialTimeout)
184185
defer cancel()
185186
}
186187

@@ -395,7 +396,7 @@ func (c *conn) NewStream(
395396
}()
396397

397398
var cancel context.CancelFunc
398-
ctx, cancel = context.WithCancel(ctx)
399+
ctx, cancel = xcontext.WithCancel(ctx)
399400

400401
defer func() {
401402
if err != nil {

0 commit comments

Comments
 (0)