Skip to content

Commit d716a3b

Browse files
authored
Merge pull request #1211 from ydb-platform/containedctx
Enabled `containedctx` linter
2 parents 9293016 + 6bbf708 commit d716a3b

31 files changed

+176
-143
lines changed

.golangci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,6 @@ linters-settings:
218218
linters:
219219
enable-all: true
220220
disable:
221-
- containedctx
222221
- contextcheck
223222
- cyclop
224223
- depguard

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Refactored internals for enabling `containedctx` linter
12
* Fixed the hanging semaphore issue on coordination session reconnect
23

34
## v3.65.3

driver.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ var _ Connection = (*Driver)(nil)
5151

5252
// Driver type provide access to YDB service clients
5353
type Driver struct {
54-
ctx context.Context // cancel while Driver.Close called.
5554
ctxCancel context.CancelFunc
5655

5756
userInfo *dsn.UserInfo
@@ -311,7 +310,6 @@ func newConnectionFromOptions(ctx context.Context, opts ...Option) (_ *Driver, e
311310

312311
d := &Driver{
313312
children: make(map[uint64]*Driver),
314-
ctx: ctx,
315313
ctxCancel: driverCtxCancel,
316314
}
317315

examples/topic/topicreader/topicreader_trace.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ func ExplicitPartitionStartStopHandler(ctx context.Context, db *ydb.Driver) {
4040
) func(
4141
trace.TopicReaderPartitionReadStartResponseDoneInfo,
4242
) {
43-
err := externalSystemLock(info.PartitionContext, info.Topic, info.PartitionID)
43+
err := externalSystemLock(*info.PartitionContext, info.Topic, info.PartitionID)
4444
if err != nil {
4545
stopReader()
4646
}
@@ -105,7 +105,7 @@ func PartitionStartStopHandlerAndOwnReadProgressStorage(ctx context.Context, db
105105
) func(
106106
trace.TopicReaderPartitionReadStartResponseDoneInfo,
107107
) {
108-
err := externalSystemLock(info.PartitionContext, info.Topic, info.PartitionID)
108+
err := externalSystemLock(*info.PartitionContext, info.Topic, info.PartitionID)
109109
if err != nil {
110110
stopReader()
111111
}

internal/background/worker.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ var (
1919

2020
// A Worker must not be copied after first use
2121
type Worker struct {
22-
ctx context.Context
22+
ctx context.Context //nolint:containedctx
2323
workers sync.WaitGroup
2424
closeReason error
2525
tasksCompleted empty.Chan

internal/conn/conn.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -462,7 +462,6 @@ func (c *conn) NewStream(
462462

463463
return &grpcClientStream{
464464
ClientStream: s,
465-
ctx: ctx,
466465
c: c,
467466
wrapping: useWrapping,
468467
traceID: traceID,

internal/conn/grpc_client_stream.go

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616

1717
type grpcClientStream struct {
1818
grpc.ClientStream
19-
ctx context.Context
2019
c *conn
2120
wrapping bool
2221
traceID string
@@ -25,9 +24,11 @@ type grpcClientStream struct {
2524
}
2625

2726
func (s *grpcClientStream) CloseSend() (err error) {
28-
ctx := s.ctx
29-
onDone := trace.DriverOnConnStreamCloseSend(s.c.config.Trace(), &ctx,
30-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).CloseSend"),
27+
var (
28+
ctx = s.Context()
29+
onDone = trace.DriverOnConnStreamCloseSend(s.c.config.Trace(), &ctx,
30+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).CloseSend"),
31+
)
3132
)
3233
defer func() {
3334
onDone(err)
@@ -60,9 +61,11 @@ func (s *grpcClientStream) CloseSend() (err error) {
6061
}
6162

6263
func (s *grpcClientStream) SendMsg(m interface{}) (err error) {
63-
ctx := s.ctx
64-
onDone := trace.DriverOnConnStreamSendMsg(s.c.config.Trace(), &ctx,
65-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).SendMsg"),
64+
var (
65+
ctx = s.Context()
66+
onDone = trace.DriverOnConnStreamSendMsg(s.c.config.Trace(), &ctx,
67+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).SendMsg"),
68+
)
6669
)
6770
defer func() {
6871
onDone(err)
@@ -79,7 +82,7 @@ func (s *grpcClientStream) SendMsg(m interface{}) (err error) {
7982
}
8083

8184
defer func() {
82-
s.c.onTransportError(s.Context(), err)
85+
s.c.onTransportError(ctx, err)
8386
}()
8487

8588
if s.wrapping {
@@ -103,9 +106,11 @@ func (s *grpcClientStream) SendMsg(m interface{}) (err error) {
103106
}
104107

105108
func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
106-
ctx := s.ctx
107-
onDone := trace.DriverOnConnStreamRecvMsg(s.c.config.Trace(), &ctx,
108-
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).RecvMsg"),
109+
var (
110+
ctx = s.Context()
111+
onDone = trace.DriverOnConnStreamRecvMsg(s.c.config.Trace(), &ctx,
112+
stack.FunctionID("github.com/ydb-platform/ydb-go-sdk/3/internal/conn.(*grpcClientStream).RecvMsg"),
113+
)
109114
)
110115
defer func() {
111116
onDone(err)
@@ -130,7 +135,7 @@ func (s *grpcClientStream) RecvMsg(m interface{}) (err error) {
130135

131136
defer func() {
132137
if !xerrors.Is(err, io.EOF) {
133-
s.c.onTransportError(s.Context(), err)
138+
s.c.onTransportError(ctx, err)
134139
}
135140
}()
136141

internal/coordination/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ func TestDescribeNodeRequest(t *testing.T) {
128128
func TestOperationParams(t *testing.T) {
129129
for _, tt := range []struct {
130130
name string
131-
ctx context.Context
131+
ctx context.Context //nolint:containedctx
132132
config interface {
133133
OperationTimeout() time.Duration
134134
OperationCancelAfter() time.Duration

internal/coordination/session.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ type session struct {
2323
options *options.CreateSessionOptions
2424
client *Client
2525

26-
ctx context.Context
26+
ctx context.Context //nolint:containedctx
2727
cancel context.CancelFunc
2828
sessionClosedChan chan struct{}
2929
controller *conversation.Controller
@@ -37,7 +37,7 @@ type session struct {
3737
type lease struct {
3838
session *session
3939
name string
40-
ctx context.Context
40+
ctx context.Context //nolint:containedctx
4141
cancel context.CancelFunc
4242
}
4343

internal/meta/context_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
func TestContext(t *testing.T) {
1212
for _, tt := range []struct {
1313
name string
14-
ctx context.Context
14+
ctx context.Context //nolint:containedctx
1515
header string
1616
values []string
1717
}{

0 commit comments

Comments
 (0)