From c08ce96076c40c7c5a9d79fbe9982c107275e50e Mon Sep 17 00:00:00 2001 From: Miguel de la Cruz Date: Thu, 28 Apr 2022 19:58:17 +0200 Subject: [PATCH] Remove timeout from MySQL migrations (#2974) --- server/services/store/sqlstore/migrate.go | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/server/services/store/sqlstore/migrate.go b/server/services/store/sqlstore/migrate.go index e4d0f2a33..33e5a4e31 100644 --- a/server/services/store/sqlstore/migrate.go +++ b/server/services/store/sqlstore/migrate.go @@ -57,6 +57,16 @@ func appendMultipleStatementsFlag(connectionString string) (string, error) { return config.FormatDSN(), nil } +// resetReadTimeout removes the timeout contraint from the MySQL dsn. +func resetReadTimeout(dataSource string) (string, error) { + config, err := mysqldriver.ParseDSN(dataSource) + if err != nil { + return "", err + } + config.ReadTimeout = 0 + return config.FormatDSN(), nil +} + // migrations in MySQL need to run with the multiStatements flag // enabled, so this method creates a new connection ensuring that it's // enabled. @@ -64,7 +74,12 @@ func (s *SQLStore) getMigrationConnection() (*sql.DB, error) { connectionString := s.connectionString if s.dbType == model.MysqlDBType { var err error - connectionString, err = appendMultipleStatementsFlag(s.connectionString) + connectionString, err = resetReadTimeout(connectionString) + if err != nil { + return nil, err + } + + connectionString, err = appendMultipleStatementsFlag(connectionString) if err != nil { return nil, err }