[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>
Этот коммит содержится в:
Claudio Costa
2021-05-17 13:26:28 +02:00
коммит произвёл GitHub
родитель ec78dcaf6e
Коммит 09f99e2426
2 изменённых файлов: 44 добавлений и 1 удалений

Просмотреть файл

@@ -351,7 +351,20 @@ func (ss *SqlStore) Context() context.Context {
}
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 {
ss.Replicas = make([]*gorp.DbMap, len(ss.settings.DataSourceReplicas))
@@ -1489,6 +1502,15 @@ func (ss *SqlStore) appendMultipleStatementsFlag(dataSource string) (string, err
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{}
func (me mattermConverter) ToDb(val interface{}) (interface{}, error) {