@@ -125,17 +125,11 @@ func (mc *mysqlConn) writePacket(data []byte) error {
125
125
126
126
n , err := mc .netConn .Write (data [:4 + size ])
127
127
if err != nil {
128
+ mc .cleanup ()
128
129
if cerr := mc .canceled .Value (); cerr != nil {
129
130
return cerr
130
131
}
131
- mc .cleanup ()
132
- if n == 0 && pktLen == len (data )- 4 {
133
- // only for the first loop iteration when nothing was written yet
134
- mc .log (err )
135
- return errBadConnNoWrite
136
- } else {
137
- return err
138
- }
132
+ return err
139
133
}
140
134
if n != 4 + size {
141
135
// io.Writer(b) must return a non-nil error if it cannot write len(b) bytes.
@@ -305,8 +299,8 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
305
299
data , err := mc .buf .takeBuffer (pktLen + 4 )
306
300
if err != nil {
307
301
// cannot take the buffer. Something must be wrong with the connection
308
- mc .log ( err )
309
- return errBadConnNoWrite
302
+ mc .cleanup ( )
303
+ return err
310
304
}
311
305
312
306
// ClientFlags [32 bit]
@@ -395,8 +389,8 @@ func (mc *mysqlConn) writeAuthSwitchPacket(authData []byte) error {
395
389
data , err := mc .buf .takeBuffer (pktLen )
396
390
if err != nil {
397
391
// cannot take the buffer. Something must be wrong with the connection
398
- mc .log ( err )
399
- return errBadConnNoWrite
392
+ mc .cleanup ( )
393
+ return err
400
394
}
401
395
402
396
// Add the auth data [EOF]
@@ -415,8 +409,8 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error {
415
409
data , err := mc .buf .takeSmallBuffer (4 + 1 )
416
410
if err != nil {
417
411
// cannot take the buffer. Something must be wrong with the connection
418
- mc .log ( err )
419
- return errBadConnNoWrite
412
+ mc .cleanup ( )
413
+ return err
420
414
}
421
415
422
416
// Add command byte
@@ -434,8 +428,8 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error {
434
428
data , err := mc .buf .takeBuffer (pktLen + 4 )
435
429
if err != nil {
436
430
// cannot take the buffer. Something must be wrong with the connection
437
- mc .log ( err )
438
- return errBadConnNoWrite
431
+ mc .cleanup ( )
432
+ return err
439
433
}
440
434
441
435
// Add command byte
@@ -455,8 +449,8 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error {
455
449
data , err := mc .buf .takeSmallBuffer (4 + 1 + 4 )
456
450
if err != nil {
457
451
// cannot take the buffer. Something must be wrong with the connection
458
- mc .log ( err )
459
- return errBadConnNoWrite
452
+ mc .cleanup ( )
453
+ return err
460
454
}
461
455
462
456
// Add command byte
@@ -998,8 +992,8 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
998
992
}
999
993
if err != nil {
1000
994
// cannot take the buffer. Something must be wrong with the connection
1001
- mc .log ( err )
1002
- return errBadConnNoWrite
995
+ mc .cleanup ( )
996
+ return err
1003
997
}
1004
998
1005
999
// command [1 byte]
@@ -1197,8 +1191,8 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
1197
1191
if valuesCap != cap (paramValues ) {
1198
1192
data = append (data [:pos ], paramValues ... )
1199
1193
if err = mc .buf .store (data ); err != nil {
1200
- mc .log ( err )
1201
- return errBadConnNoWrite
1194
+ mc .cleanup ( )
1195
+ return err
1202
1196
}
1203
1197
}
1204
1198
0 commit comments