@@ -367,7 +367,7 @@ func (db *DB) BeginTx(options ...transaction.Option) (tx transaction.Transaction
367
367
return nil , err
368
368
}
369
369
370
- rawTx , err := db .DB .BeginTxx (params .Context , sqlOptions )
370
+ rawTx , err := db .DB .BeginTxx (safeMysqlContext ( params .Context ) , sqlOptions )
371
371
if err != nil {
372
372
db .updateCounter (1 , "begin.failed" )
373
373
return nil , err
@@ -583,7 +583,7 @@ func (tx *Transaction) Exec(ctx context.Context, sql string, args ...interface{}
583
583
584
584
func (tx * Transaction ) exec (ctx context.Context , sql string , args ... interface {}) error {
585
585
tx .logQuery (sql , args ... )
586
- _ , err := tx .transaction .ExecContext (ctx , sql , args ... )
586
+ _ , err := tx .transaction .ExecContext (safeMysqlContext ( ctx ) , sql , args ... )
587
587
return err
588
588
}
589
589
@@ -856,7 +856,7 @@ func buildSelect(sc *selectContext) (string, []interface{}, error) {
856
856
857
857
func (tx * Transaction ) executeSelect (ctx context.Context , sc * selectContext , sql string , args []interface {}) (list []* schema.Resource , total uint64 , err error ) {
858
858
tx .logQuery (sql , args ... )
859
- rows , err := tx .transaction .QueryxContext (ctx , sql , args ... )
859
+ rows , err := tx .transaction .QueryxContext (safeMysqlContext ( ctx ) , sql , args ... )
860
860
if err != nil {
861
861
return
862
862
}
@@ -955,7 +955,7 @@ func (tx *Transaction) Query(ctx context.Context, s *schema.Schema, query string
955
955
defer tx .measureTime (time .Now (), s .ID , "query" )
956
956
957
957
tx .logQuery (query , arguments ... )
958
- rows , err := tx .transaction .QueryxContext (ctx , query , arguments ... )
958
+ rows , err := tx .transaction .QueryxContext (safeMysqlContext ( ctx ) , query , arguments ... )
959
959
if err != nil {
960
960
return nil , fmt .Errorf ("Failed to run query: %s" , query )
961
961
}
@@ -1022,7 +1022,7 @@ func (tx *Transaction) Count(ctx context.Context, s *schema.Schema, filter trans
1022
1022
return
1023
1023
}
1024
1024
result := map [string ]interface {}{}
1025
- err = tx .transaction .QueryRowxContext (ctx , sql , args ... ).MapScan (result )
1025
+ err = tx .transaction .QueryRowxContext (safeMysqlContext ( ctx ) , sql , args ... ).MapScan (result )
1026
1026
if err != nil {
1027
1027
return
1028
1028
}
@@ -1089,7 +1089,7 @@ func (tx *Transaction) StateFetch(ctx context.Context, s *schema.Schema, filter
1089
1089
return
1090
1090
}
1091
1091
tx .logQuery (sql , args ... )
1092
- rows , err := tx .transaction .QueryxContext (ctx , sql , args ... )
1092
+ rows , err := tx .transaction .QueryxContext (safeMysqlContext ( ctx ) , sql , args ... )
1093
1093
if err != nil {
1094
1094
return
1095
1095
}
@@ -1265,3 +1265,10 @@ func (db *DB) SetMaxOpenConns(maxIdleConns int) {
1265
1265
// db.DB.SetMaxOpenConns(maxIdleConns)
1266
1266
// db.DB.SetMaxIdleConns(maxIdleConns)
1267
1267
}
1268
+
1269
+ // Mysql driver does not support graceful cancellation via context.Cancel()
1270
+ // This function (and its usages) should be removed when (if) this defect got fixed:
1271
+ // https://github.com/go-sql-driver/mysql/issues/731
1272
+ func safeMysqlContext (_ context.Context ) context.Context {
1273
+ return context .Background ()
1274
+ }
0 commit comments