go-zero
go-zero copied to clipboard
How to set timeout params in sqlx.NewMysql
Hi,
I want to set some mysql params (e.g. timeout), but I found the SqlOption is private var.
func NewMysql(datasource string, opts ...SqlOption) SqlConn {
opts = append(opts, withMysqlAcceptable())
return NewSqlConn(mysqlDriverName, datasource, opts...)
}
SqlOption func(*commonSqlConn)
So how to fix or workaround?
I found a workaround. Add timeout params in Mysql DSN string, but it not what my expect . So how to fix it?
Is there any progress?
Is there any progress?
Has left six days, but there is no progress .... π
Open 10 days ago, no progress still ...
Bot detected the issue body's language is not English, translate it automatically. π―ππ»π§βπ€βπ§π«π§πΏβπ€βπ§π»π©πΎβπ€βπ¨πΏπ¬πΏ
Open 10 days ago, no progress still ...
Open 18 days ago, no progress still ...
Sorry, but what timeout do you want to set? Dial or exec?
Dial , the Ping phase, to be exact.. I expect to control the timeout when execute Ping(). If ping failed, then it will quick failure
Did you encounter any problem so far?
Would you give a detail example on the scenarios?
in core/stores/sqlx/sqlmanager.go L43
func getSqlConn(driverName, server string) (*sql.DB, error) {
pdb, err := getCachedSqlConn(driverName, server)
if err != nil {
return nil, err
}
pdb.once.Do(func() {
err = pdb.Ping()
})
if err != nil {
return nil, err
}
return pdb.DB, nil
}
If mysql connect failed, the Ping() will hang about 30s. In fact, we needn't this hang time. So I want to add some timeout params in NewMysql with SqlOption (e.g. 5s for ping timeout).
func NewMysql(datasource string, opts ...SqlOption) SqlConn {
opts = append(opts, withMysqlAcceptable())
return NewSqlConn(mysqlDriverName, datasource, opts...)
}
But SqlOption func(*commonSqlConn)
is private var, I can not use it in my code. Now I use mysql dsn with timeout params.
I want to know , is there has other ways to change it?
If you wants to get more detail info, please let know.
Open 25 days ago, no substantial progress, and I think there has a inactive community
Didn't figure out a good solution. I read but no reply, sorry.
I found a workaround. Add timeout params in Mysql DSN string, but it not what my expect . So how to fix it?
I think the timeout params in DSN is already a better soluion.
This issue is stale because it has been open for 30 days with no activity.
This issue was closed because it has been inactive for 14 days since being marked as stale.