Your Question
出发点是想设置全局的查询超时时间
看了 https://github.com/go-sql-driver/mysql#readtimeout 这里的介绍,我在 DSN 中参入了 &readTimeout=1ms&writeTimeout=6ms 来测试验证超时,但是经验证并没有生效。
The document you expected this should be explained
超过了 1ms 的查询,并没有出现查询超时异常
Expected answer
看了 gorm 的 mysql driver 依赖的是 github.com/go-sql-driver/mysql ,理论上应该是能生效才对,请问是不是有 bug?
或者说,gorm 有没有其他的方式来设置全局的查询超时时间?
Comment From: github-actions[bot]
The issue has been automatically marked as stale as it missing playground pull request link, which is important to help others understand your issue effectively and make sure the issue hasn't been fixed on latest master, checkout https://github.com/go-gorm/playground for details. it will be closed in 30 days if no further activity occurs. if you are asking question, please use the Question template, most likely your question already answered https://github.com/go-gorm/gorm/issues or described in the document https://gorm.io ✨ Search Before Asking ✨
Comment From: a631807682
- The time of the log print is not the time of the actual query.
- Each data queried by mysql will be returned immediately, all records are completed by waiting on the client side.
you can use DB.Raw("select sleep(1)") to test it.
Comment From: rason
DB.Raw("select sleep(1)")
I tried this and readTimeout didn't work.
Comment From: chengjk
DB.Raw("select sleep(1)")
I tried this and readTimeout didn't work.
DB.Raw("select sleep(1)").Scan(nil)
Comment From: whling
How to resolve it finally?