Skip to content

Commit e931dfb

Browse files
committed
external wait group on closing table-client step
1 parent 89e6c3c commit e931dfb

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

internal/table/client.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -537,18 +537,28 @@ func (c *Client) Close(ctx context.Context) (err error) {
537537

538538
if atomic.CompareAndSwapUint32(&c.closed, 0, 1) {
539539
close(c.done)
540+
541+
wg := sync.WaitGroup{}
540542
c.mu.WithLock(func() {
543+
c.limit = 0
544+
541545
for el := c.waitq.Front(); el != nil; el = el.Next() {
542546
ch := el.Value.(*chan *session)
543547
close(*ch)
544548
}
545549

546550
for e := c.idle.Front(); e != nil; e = e.Next() {
547-
c.internalPoolAsyncCloseSession(ctx, e.Value.(*session))
551+
wg.Add(1)
552+
s := e.Value.(*session)
553+
s.SetStatus(options.SessionClosing)
554+
go func() {
555+
defer wg.Done()
556+
c.internalPoolSyncCloseSession(ctx, s)
557+
}()
548558
}
549-
550-
c.limit = 0
551559
})
560+
wg.Wait()
561+
552562
c.spawnedGoroutines.Wait()
553563
}
554564

0 commit comments

Comments
 (0)