@@ -353,7 +353,7 @@ func (c *Conn) PrepareContext(ctx context.Context, query string) (driver.Stmt, e
353
353
if c .tracing != client .LogNone {
354
354
start = time .Now ()
355
355
}
356
- err := c .protocol .Call (ctx , & c .request , & c .response );
356
+ err := c .protocol .Call (ctx , & c .request , & c .response )
357
357
if c .tracing != client .LogNone {
358
358
c .log (c .tracing , "%.3fs request prepared: %q" , time .Since (start ).Seconds (), query )
359
359
}
@@ -392,7 +392,7 @@ func (c *Conn) ExecContext(ctx context.Context, query string, args []driver.Name
392
392
if c .tracing != client .LogNone {
393
393
start = time .Now ()
394
394
}
395
- err := c .protocol .Call (ctx , & c .request , & c .response );
395
+ err := c .protocol .Call (ctx , & c .request , & c .response )
396
396
if c .tracing != client .LogNone {
397
397
c .log (c .tracing , "%.3fs request exec: %q" , time .Since (start ).Seconds (), query )
398
398
}
@@ -428,7 +428,7 @@ func (c *Conn) QueryContext(ctx context.Context, query string, args []driver.Nam
428
428
if c .tracing != client .LogNone {
429
429
start = time .Now ()
430
430
}
431
- err := c .protocol .Call (ctx , & c .request , & c .response );
431
+ err := c .protocol .Call (ctx , & c .request , & c .response )
432
432
if c .tracing != client .LogNone {
433
433
c .log (c .tracing , "%.3fs request query: %q" , time .Since (start ).Seconds (), query )
434
434
}
@@ -588,7 +588,7 @@ func (s *Stmt) ExecContext(ctx context.Context, args []driver.NamedValue) (drive
588
588
if s .tracing != client .LogNone {
589
589
start = time .Now ()
590
590
}
591
- err := s .protocol .Call (ctx , s .request , s .response );
591
+ err := s .protocol .Call (ctx , s .request , s .response )
592
592
if s .tracing != client .LogNone {
593
593
s .log (s .tracing , "%.3fs request prepared: %q" , time .Since (start ).Seconds (), s .sql )
594
594
}
@@ -627,7 +627,7 @@ func (s *Stmt) QueryContext(ctx context.Context, args []driver.NamedValue) (driv
627
627
if s .tracing != client .LogNone {
628
628
start = time .Now ()
629
629
}
630
- err := s .protocol .Call (ctx , s .request , s .response );
630
+ err := s .protocol .Call (ctx , s .request , s .response )
631
631
if s .tracing != client .LogNone {
632
632
s .log (s .tracing , "%.3fs request prepared: %q" , time .Since (start ).Seconds (), s .sql )
633
633
}
@@ -787,6 +787,12 @@ type unwrappable interface {
787
787
Unwrap () error
788
788
}
789
789
790
+ // TODO driver.ErrBadConn should not be returned when there's a possibility that
791
+ // the query has been executed. In our case there is a window in protocol.Call
792
+ // between `send` and `recv` where the send has succeeded but the recv has
793
+ // failed. In those cases we call driverError on the result of protocol.Call,
794
+ // possibly returning ErrBadCon.
795
+ // https://cs.opensource.google/go/go/+/refs/tags/go1.20.4:src/database/sql/driver/driver.go;drc=a32a592c8c14927c20ac42808e1fb2e55b2e9470;l=162
790
796
func driverError (log client.LogFunc , err error ) error {
791
797
switch err := errors .Cause (err ).(type ) {
792
798
case syscall.Errno :
@@ -837,5 +843,9 @@ func driverError(log client.LogFunc, err error) error {
837
843
return driver .ErrBadConn
838
844
}
839
845
}
846
+ if errors .Is (err , io .EOF ) {
847
+ log (client .LogDebug , "EOF detected: %v" , err )
848
+ return driver .ErrBadConn
849
+ }
840
850
return err
841
851
}
0 commit comments