@@ -24,9 +24,9 @@ import (
2424)
2525
2626var (
27- // errSessionPoolClosed returned by a client instance to indicate
28- // that client is closed and not able to complete requested operation.
29- errSessionPoolClosed = xerrors .Wrap (fmt .Errorf ("session pool is closed" ))
27+ // errAlreadyClosed returned by a client instance to indicate
28+ // that client is closed early and not able to complete requested operation.
29+ errAlreadyClosed = xerrors .Wrap (fmt .Errorf ("table client closed early " ))
3030
3131 // errSessionPoolOverflow returned by a client instance to indicate
3232 // that the client is full and requested operation is not able to complete.
@@ -52,18 +52,20 @@ type Client interface {
5252 CloseSession (ctx context.Context , s Session ) (err error )
5353}
5454
55- func New (ctx context. Context , cc grpc.ClientConnInterface , opts ... config.Option ) Client {
55+ func New (cc grpc.ClientConnInterface , opts [] config.Option ) Client {
5656 config := config .New (opts ... )
57- return newClient (ctx , cc , nil , config )
57+ return newClient (cc , nil , config )
5858}
5959
6060func newClient (
61- ctx context.Context ,
6261 cc grpc.ClientConnInterface ,
6362 builder SessionBuilder ,
6463 config config.Config ,
6564) * client {
66- onDone := trace .TableOnInit (config .Trace (), & ctx )
65+ var (
66+ ctx = context .Background ()
67+ onDone = trace .TableOnInit (config .Trace (), & ctx )
68+ )
6769 if builder == nil {
6870 builder = func (ctx context.Context ) (s Session , err error ) {
6971 return newSession (ctx , cc , config )
@@ -315,7 +317,7 @@ func (c *client) get(ctx context.Context, opts ...getOption) (s Session, err err
315317 const maxAttempts = 100
316318 for ; s == nil && err == nil && i < maxAttempts ; i ++ {
317319 if c .isClosed () {
318- return nil , xerrors .WithStackTrace (errSessionPoolClosed )
320+ return nil , xerrors .WithStackTrace (errAlreadyClosed )
319321 }
320322
321323 // First, we try to get session from idle
@@ -415,7 +417,7 @@ func (c *client) waitFromCh(ctx context.Context, t trace.Table) (s Session, err
415417
416418// Put returns session to the client for further reuse.
417419// If client is already closed Put() calls s.Close(ctx) and returns
418- // errSessionPoolClosed .
420+ // errAlreadyClosed .
419421// If client is overflow calls s.Close(ctx) and returns
420422// errSessionPoolOverflow.
421423//
@@ -432,7 +434,7 @@ func (c *client) Put(ctx context.Context, s Session) (err error) {
432434
433435 switch {
434436 case c .closed :
435- err = xerrors .WithStackTrace (errSessionPoolClosed )
437+ err = xerrors .WithStackTrace (errAlreadyClosed )
436438
437439 case c .idle .Len () >= c .limit :
438440 err = xerrors .WithStackTrace (errSessionPoolOverflow )
@@ -473,7 +475,7 @@ func (c *client) Close(ctx context.Context) (err error) {
473475 }()
474476
475477 if c .isClosed () {
476- return
478+ return xerrors . WithStackTrace ( errAlreadyClosed )
477479 }
478480
479481 c .mu .Lock ()
@@ -540,7 +542,7 @@ func retryOptions(trace trace.Table, opts ...table.Option) table.Options {
540542// Warning: if deadline without deadline or cancellation func Retry will be worked infinite
541543func (c * client ) Do (ctx context.Context , op table.Operation , opts ... table.Option ) (err error ) {
542544 if c .isClosed () {
543- return xerrors .WithStackTrace (errSessionPoolClosed )
545+ return xerrors .WithStackTrace (errAlreadyClosed )
544546 }
545547 opts = append (opts , table .WithTrace (c .config .Trace ()))
546548 return do (
@@ -554,7 +556,7 @@ func (c *client) Do(ctx context.Context, op table.Operation, opts ...table.Optio
554556
555557func (c * client ) DoTx (ctx context.Context , op table.TxOperation , opts ... table.Option ) (err error ) {
556558 if c .isClosed () {
557- return xerrors .WithStackTrace (errSessionPoolClosed )
559+ return xerrors .WithStackTrace (errAlreadyClosed )
558560 }
559561 return doTx (
560562 ctx ,
0 commit comments