@@ -578,7 +578,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
578578			return  nil , w .err 
579579		}
580580
581- 		if  err  :=  awaitPendingRead (ctx , p , w .conn ); err  !=  nil  {
581+ 		if  err  :=  awaitPendingResponse (ctx , p , w .conn ); err  !=  nil  {
582582			return  nil , err 
583583		}
584584
@@ -638,7 +638,7 @@ func (p *pool) checkOut(ctx context.Context) (conn *connection, err error) {
638638			return  nil , w .err 
639639		}
640640
641- 		if  err  :=  awaitPendingRead (ctx , p , w .conn ); err  !=  nil  {
641+ 		if  err  :=  awaitPendingResponse (ctx , p , w .conn ); err  !=  nil  {
642642			return  nil , err 
643643		}
644644
@@ -781,19 +781,18 @@ func (p *pool) removeConnection(conn *connection, reason reason, err error) erro
781781	return  nil 
782782}
783783
784- // PendingReadTimeout is the maximum amount of the to wait when trying to read 
785- // the server reply on a connection after an operation timed out. The 
786- // default is 400 milliseconds. This value is refreshed for every 4KB read from 
787- // the TCP stream. 
784+ // PendingResponseTimeout is the maximum amount of the to wait when trying to 
785+ // read the server reply on a connection after an operation timed out. The 
786+ // default is 3000 milliseconds. 
788787// 
789- // Deprecated: PendingReadTimeout  is intended for internal use only and may be  
790- // removed or modified at any time. 
791- var  PendingReadTimeout  =  3000  *  time .Millisecond 
788+ // Deprecated: PendingResponseTimeout  is intended for internal use only and may 
789+ // be  removed or modified at any time. 
790+ var  PendingResponseTimeout  =  3000  *  time .Millisecond 
792791
793- // publishPendingReadStarted  will log a message to the pool logger and 
792+ // publishPendingResponseStarted  will log a message to the pool logger and 
794793// publish an event to the pool monitor if they are set. 
795- func  publishPendingReadStarted (pool  * pool , conn  * connection ) {
796- 	prs  :=  conn .pendingReadState 
794+ func  publishPendingResponseStarted (pool  * pool , conn  * connection ) {
795+ 	prs  :=  conn .pendingResponseState 
797796	if  prs  ==  nil  {
798797		return 
799798	}
@@ -805,7 +804,7 @@ func publishPendingReadStarted(pool *pool, conn *connection) {
805804			logger .KeyRequestID , prs .requestID ,
806805		}
807806
808- 		logPoolMessage (pool , logger .ConnectionPendingReadStarted , keysAndValues ... )
807+ 		logPoolMessage (pool , logger .ConnectionPendingResponseStarted , keysAndValues ... )
809808	}
810809
811810	// publish an event to the pool monitor if it is set. 
@@ -821,8 +820,8 @@ func publishPendingReadStarted(pool *pool, conn *connection) {
821820	}
822821}
823822
824- func  publishPendingReadFailed (pool  * pool , conn  * connection , err  error ) {
825- 	prs  :=  conn .pendingReadState 
823+ func  publishPendingResponseFailed (pool  * pool , conn  * connection , err  error ) {
824+ 	prs  :=  conn .pendingResponseState 
826825	if  prs  ==  nil  {
827826		return 
828827	}
@@ -840,7 +839,7 @@ func publishPendingReadFailed(pool *pool, conn *connection, err error) {
840839			logger .KeyError , err .Error (),
841840		}
842841
843- 		logPoolMessage (pool , logger .ConnectionPendingReadFailed , keysAndValues ... )
842+ 		logPoolMessage (pool , logger .ConnectionPendingResponseFailed , keysAndValues ... )
844843	}
845844
846845	if  pool .monitor  !=  nil  {
@@ -856,8 +855,8 @@ func publishPendingReadFailed(pool *pool, conn *connection, err error) {
856855	}
857856}
858857
859- func  publishPendingReadSucceeded (pool  * pool , conn  * connection , dur  time.Duration ) {
860- 	prs  :=  conn .pendingReadState 
858+ func  publishPendingResponseSucceeded (pool  * pool , conn  * connection , dur  time.Duration ) {
859+ 	prs  :=  conn .pendingResponseState 
861860	if  prs  ==  nil  {
862861		return 
863862	}
@@ -869,7 +868,7 @@ func publishPendingReadSucceeded(pool *pool, conn *connection, dur time.Duration
869868			logger .KeyDurationMS , dur .Milliseconds (),
870869		}
871870
872- 		logPoolMessage (pool , logger .ConnectionPendingReadSucceeded , keysAndValues ... )
871+ 		logPoolMessage (pool , logger .ConnectionPendingResponseSucceeded , keysAndValues ... )
873872	}
874873
875874	if  pool .monitor  !=  nil  {
@@ -901,8 +900,8 @@ func peekConnectionAlive(conn *connection) (int, error) {
901900	return  len (bytes ), err 
902901}
903902
904- func  attemptPendingRead (ctx  context.Context , conn  * connection , remainingTime  time.Duration ) (int , error ) {
905- 	pendingreadState  :=  conn .pendingReadState 
903+ func  attemptPendingResponse (ctx  context.Context , conn  * connection , remainingTime  time.Duration ) (int , error ) {
904+ 	pendingreadState  :=  conn .pendingResponseState 
906905	if  pendingreadState  ==  nil  {
907906		return  0 , fmt .Errorf ("no pending read state" )
908907	}
@@ -986,25 +985,25 @@ func attemptPendingRead(ctx context.Context, conn *connection, remainingTime tim
986985	return  int (totalRead ), nil 
987986}
988987
989- // awaitPendingRead  sets a new read deadline on the provided connection and 
988+ // awaitPendingResponse  sets a new read deadline on the provided connection and 
990989// tries to read any bytes returned by the server. If there are any errors, the 
991990// connection will be checked back into the pool to be retried. 
992- func  awaitPendingRead (ctx  context.Context , pool  * pool , conn  * connection ) error  {
993- 	conn .pendingReadMu .Lock ()
994- 	defer  conn .pendingReadMu .Unlock ()
991+ func  awaitPendingResponse (ctx  context.Context , pool  * pool , conn  * connection ) error  {
992+ 	conn .pendingResponseStateMu .Lock ()
993+ 	defer  conn .pendingResponseStateMu .Unlock ()
995994
996995	// If there are no bytes pending read, do nothing. 
997- 	if  conn .pendingReadState  ==  nil  {
996+ 	if  conn .pendingResponseState  ==  nil  {
998997		return  nil 
999998	}
1000999
1001- 	publishPendingReadStarted (pool , conn )
1000+ 	publishPendingResponseStarted (pool , conn )
10021001
10031002	var  (
1004- 		pendingReadState  =  conn .pendingReadState 
1005- 		remainingTime     =   pendingReadState .start .Add (PendingReadTimeout ).Sub (time .Now ())
1006- 		err               error 
1007- 		bytesRead         int 
1003+ 		pendingResponseState  =  conn .pendingResponseState 
1004+ 		remainingTime          =   pendingResponseState .start .Add (PendingResponseTimeout ).Sub (time .Now ())
1005+ 		err                    error 
1006+ 		bytesRead              int 
10081007	)
10091008
10101009	st  :=  time .Now ()
@@ -1013,7 +1012,7 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
10131012		// aliveness. In such cases, we don't want to close the connection. 
10141013		bytesRead , err  =  peekConnectionAlive (conn )
10151014	} else  {
1016- 		bytesRead , err  =  attemptPendingRead (ctx , conn , remainingTime )
1015+ 		bytesRead , err  =  attemptPendingResponse (ctx , conn , remainingTime )
10171016	}
10181017
10191018	endTime  :=  time .Now ()
@@ -1029,13 +1028,12 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
10291028		// operations. This is likely a bug in the Go Driver. So it's possible that 
10301029		// the connection is idle at the point of check-in. 
10311030		defer  func () {
1032- 			publishPendingReadFailed (pool , conn , err )
1031+ 			publishPendingResponseFailed (pool , conn , err )
10331032
10341033			_  =  pool .checkInNoEvent (conn )
10351034		}()
10361035
10371036		if  netErr , ok  :=  err .(net.Error ); ok  &&  ! netErr .Timeout () {
1038- 			fmt .Println (1 )
10391037			if  err  :=  conn .close (); err  !=  nil  {
10401038				return  err 
10411039			}
@@ -1045,11 +1043,11 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
10451043
10461044	// If the read was successful, then we should refresh the remaining timeout. 
10471045	if  bytesRead  >  0  {
1048- 		pendingReadState .start  =  endTime 
1046+ 		pendingResponseState .start  =  endTime 
10491047	}
10501048
10511049	// If the remaining time has been exceeded, then close the connection. 
1052- 	if  endTime .Sub (pendingReadState .start ) >  PendingReadTimeout  {
1050+ 	if  endTime .Sub (pendingResponseState .start ) >  PendingResponseTimeout  {
10531051		if  err  :=  conn .close (); err  !=  nil  {
10541052			return  err 
10551053		}
@@ -1059,9 +1057,9 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
10591057		return  err 
10601058	}
10611059
1062- 	publishPendingReadSucceeded (pool , conn , endDuration )
1060+ 	publishPendingResponseSucceeded (pool , conn , endDuration )
10631061
1064- 	conn .pendingReadState  =  nil 
1062+ 	conn .pendingResponseState  =  nil 
10651063
10661064	return  nil 
10671065}
0 commit comments