@@ -791,7 +791,7 @@ func (p *pool) removeConnection(conn *connection, reason reason, err error) erro
791791// Deprecated: PendingReadTimeout is intended for internal use only and may be
792792// removed or modified at any time.
793793
794- var PendingReadTimeout = 1 * time .Second
794+ var PendingReadTimeout = 400 * time .Millisecond
795795
796796// awaitPendingRead sets a new read deadline on the provided connection and
797797// tries to read any bytes returned by the server. If there are any errors, the
@@ -805,18 +805,32 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
805805 return nil
806806 }
807807
808- //if pool.monitor != nil {
809- // pool.monitor.Event(&event.PoolEvent{
810- // Type: event.ConnectionPendingReadStarted,
811- // ConnectionID: conn.driverConnectionID,
812- // })
813- //}
808+ if mustLogPoolMessage (pool ) {
809+ keysAndValues := logger.KeyValues {
810+ logger .KeyDriverConnectionID , conn .driverConnectionID ,
811+ logger .KeyRequestID , conn .requestID ,
812+ }
813+
814+ logPoolMessage (pool , logger .ConnectionPendingReadStarted , keysAndValues ... )
815+ }
814816
815817 size := * conn .awaitRemainingBytes
816818
817819 checkIn := false
820+ var someErr error
818821
819822 defer func () {
823+ if mustLogPoolMessage (pool ) && someErr != nil {
824+ keysAndValues := logger.KeyValues {
825+ logger .KeyDriverConnectionID , conn .driverConnectionID ,
826+ logger .KeyRequestID , conn .requestID ,
827+ logger .KeyReason , someErr .Error (),
828+ logger .KeyRemainingTimeMS , * conn .remainingTime ,
829+ }
830+
831+ logPoolMessage (pool , logger .ConnectionPendingReadFailed , keysAndValues ... )
832+ }
833+
820834 // If we have exceeded the time limit, then close the connection.
821835 if conn .remainingTime != nil && * conn .remainingTime < 0 {
822836 if err := conn .close (); err != nil {
@@ -830,14 +844,6 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
830844 return
831845 }
832846
833- //if pool.monitor != nil {
834- // pool.monitor.Event(&event.PoolEvent{
835- // Type: event.ConnectionPendingReadFailed,
836- // ConnectionID: conn.driverConnectionID,
837- // //Reason: readErr.Error(),
838- // })
839- //}
840-
841847 // No matter what happens, always check the connection back into the
842848 // pool, which will either make it available for other operations or
843849 // remove it from the pool if it was closed.
@@ -857,7 +863,10 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
857863 err := conn .nc .SetReadDeadline (dl )
858864 if err != nil {
859865 checkIn = true
860- return fmt .Errorf ("error setting a read deadline: %w" , err )
866+
867+ someErr = fmt .Errorf ("error setting a read deadline: %w" , err )
868+
869+ return someErr
861870 }
862871
863872 st := time .Now ()
@@ -869,15 +878,16 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
869878 checkIn = true
870879
871880 err = transformNetworkError (ctx , err , contextDeadlineUsed )
881+ someErr = fmt .Errorf ("error reading the message size: %w" , err )
872882
873- return fmt . Errorf ( "error reading the message size: %w" , err )
883+ return someErr
874884 }
875885 size , err = conn .parseWmSizeBytes (sizeBuf )
876886 if err != nil {
877887 checkIn = true
878- err = transformNetworkError (ctx , err , contextDeadlineUsed )
888+ someErr = transformNetworkError (ctx , err , contextDeadlineUsed )
879889
880- return err
890+ return someErr
881891 }
882892 size -= 4
883893 }
@@ -893,17 +903,19 @@ func awaitPendingRead(ctx context.Context, pool *pool, conn *connection) error {
893903 checkIn = true
894904
895905 err = transformNetworkError (ctx , err , contextDeadlineUsed )
906+ someErr = fmt .Errorf ("error discarding %d byte message: %w" , size , err )
896907
897- return fmt . Errorf ( "error discarding %d byte message: %w" , size , err )
908+ return someErr
898909 }
899910
900- //if pool.monitor != nil {
901- // pool.monitor.Event(&event.PoolEvent{
902- // Type: event.ConnectionPendingReadSucceeded,
903- // ConnectionID: conn.driverConnectionID,
904- // //Reason: readErr.Error(),
905- // })
906- //}
911+ if mustLogPoolMessage (pool ) {
912+ keysAndValues := logger.KeyValues {
913+ logger .KeyDriverConnectionID , conn .driverConnectionID ,
914+ logger .KeyRequestID , conn .requestID ,
915+ }
916+
917+ logPoolMessage (pool , logger .ConnectionPendingReadSucceeded , keysAndValues ... )
918+ }
907919
908920 conn .awaitRemainingBytes = nil
909921 conn .remainingTime = nil
0 commit comments