Skip to content

Commit 2de3963

Browse files
committed
fix race
1 parent c7bdec9 commit 2de3963

File tree

2 files changed

+9
-7
lines changed

2 files changed

+9
-7
lines changed

internal/table/client.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -154,12 +154,14 @@ func (c *Client) createSession(ctx context.Context, opts ...createSessionOption)
154154
if s == nil {
155155
return
156156
}
157-
var cancel context.CancelFunc
158-
ctx, cancel = context.WithTimeout(
159-
xcontext.WithoutDeadline(ctx),
160-
c.config.DeleteTimeout(),
161-
)
162-
defer cancel()
157+
158+
closeSessionCtx := xcontext.WithoutDeadline(ctx)
159+
160+
if timeout := c.config.DeleteTimeout(); timeout > 0 {
161+
var cancel context.CancelFunc
162+
createSessionCtx, cancel = context.WithTimeout(closeSessionCtx, timeout)
163+
defer cancel()
164+
}
163165

164166
_ = s.Close(ctx)
165167
}

internal/table/client_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ func TestRaceWgClosed(t *testing.T) {
264264
counter++
265265
defer func() {
266266
if counter%100 == 0 {
267-
t.Logf("TestRaceWgClosed %d subtests done", counter)
267+
t.Logf("%d times test passed", counter)
268268
}
269269
}()
270270
ctx, cancel := context.WithTimeout(context.Background(),

0 commit comments

Comments
 (0)