[MM-35767] Ignore readTimeout param from MySQL datasource (#17624)
* Ignore readTimeout from MySQL datasource * Add TODO Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
ec78dcaf6e
Коммит
09f99e2426
@@ -351,7 +351,20 @@ func (ss *SqlStore) Context() context.Context {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (ss *SqlStore) initConnection() {
|
func (ss *SqlStore) initConnection() {
|
||||||
ss.master = setupConnection("master", *ss.settings.DataSource, ss.settings)
|
dataSource := *ss.settings.DataSource
|
||||||
|
if ss.DriverName() == model.DATABASE_DRIVER_MYSQL {
|
||||||
|
// TODO: We ignore the readTimeout datasource parameter for MySQL since QueryTimeout
|
||||||
|
// covers that already. Ideally we'd like to do this only for the upgrade
|
||||||
|
// step. To be reviewed in MM-35789.
|
||||||
|
var err error
|
||||||
|
dataSource, err = resetReadTimeout(dataSource)
|
||||||
|
if err != nil {
|
||||||
|
mlog.Critical("Failed to reset read timeout from datasource.", mlog.Err(err))
|
||||||
|
os.Exit(ExitGenericFailure)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ss.master = setupConnection("master", dataSource, ss.settings)
|
||||||
|
|
||||||
if len(ss.settings.DataSourceReplicas) > 0 {
|
if len(ss.settings.DataSourceReplicas) > 0 {
|
||||||
ss.Replicas = make([]*gorp.DbMap, len(ss.settings.DataSourceReplicas))
|
ss.Replicas = make([]*gorp.DbMap, len(ss.settings.DataSourceReplicas))
|
||||||
@@ -1489,6 +1502,15 @@ func (ss *SqlStore) appendMultipleStatementsFlag(dataSource string) (string, err
|
|||||||
return dataSource, nil
|
return dataSource, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func resetReadTimeout(dataSource string) (string, error) {
|
||||||
|
config, err := mysql.ParseDSN(dataSource)
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
config.ReadTimeout = 0
|
||||||
|
return config.FormatDSN(), nil
|
||||||
|
}
|
||||||
|
|
||||||
type mattermConverter struct{}
|
type mattermConverter struct{}
|
||||||
|
|
||||||
func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
|
func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"regexp"
|
"regexp"
|
||||||
"sync"
|
"sync"
|
||||||
"testing"
|
"testing"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/go-sql-driver/mysql"
|
"github.com/go-sql-driver/mysql"
|
||||||
"github.com/lib/pq"
|
"github.com/lib/pq"
|
||||||
@@ -674,3 +675,23 @@ func TestExecNoTimeout(t *testing.T) {
|
|||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestMySQLReadTimeout(t *testing.T) {
|
||||||
|
settings := makeSqlSettings(model.DATABASE_DRIVER_MYSQL)
|
||||||
|
dataSource := *settings.DataSource
|
||||||
|
config, err := mysql.ParseDSN(dataSource)
|
||||||
|
require.NoError(t, err)
|
||||||
|
|
||||||
|
config.ReadTimeout = 1 * time.Second
|
||||||
|
dataSource = config.FormatDSN()
|
||||||
|
settings.DataSource = &dataSource
|
||||||
|
|
||||||
|
store := &SqlStore{
|
||||||
|
settings: settings,
|
||||||
|
}
|
||||||
|
store.initConnection()
|
||||||
|
defer store.Close()
|
||||||
|
|
||||||
|
_, err = store.GetMaster().ExecNoTimeout(`SELECT SLEEP(3)`)
|
||||||
|
require.NoError(t, err)
|
||||||
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user