-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
About DB connection random lost #6804
Comments
I'm getting the same kinds of errors: ==> /home/gitea/log/gitea.log <== Seems to be pretty random and manifesting as 500/404 errors, sometimes on git push/pull and others also while navigating the web fronted. A retry/refresh of the same URL seems to always succeed straight away. I'm using Gitea 1.8.1 Not seeing anything in MySQL log, but maybe I haven't enabled it verbose enough. |
I think this should be a go-sql-driver/mysql 's problem. |
How does go load the driver? Is it all packaged into the binary? I didn't have to install any dependencies, so I'm guessing there isn't anything I can update on the OS level, apart from MySQL itself perhaps? |
I've upgraded MySQL to 5.7.26 and still experiencing this. The error in mysql.log is |
Could it be that xorm does not close connection at same cases (go-sql-driver/mysql#556)? |
Yeah I reckon it could be. I've been sitting tailing the logs for a bit and it seems that the mysql timeout comes FIRST. Then next page refresh I get the 404/500 error accompanied by the GO error "GetUserById: invalid connection" and this is 100% repeatable. Now also watching the MySQL process list. What it looks like is happening:
So, I'm guessing Gitea is (efficiently) only opening one connection, and keeping it idle until it needs to use it again? However when that time comes, if the connection is no longer available this is not caught properly to re-open the connection and retry the last query. I can increase my mysql timeout, but this will only make the errors less frequent. Unless Gitea closes the connection after a set time, in which case if I make the mysql timeout greater than this it should solve it? Should Gitea be closing its connection after use or is it by design keeping it open? |
I think golang MySQL library is keeping pool of open connections to reuse them but it should have reopen new one if current one has become invalid ihmo |
I've tried setting mysql timeout on the server to 120, 180 and 300 and each time the connection times out, I hit a page and get the error still. I've now set the timeout to 3000 and been watching the logs and processes, it seems Gitea has an internal cron that is making a query every 10 mins, this is essentially acting as a keep alive heartbeat that keeps resetting the connection sleep time.
This looks like a maintenance task and not a real keep alive implementation, so its a bit of a crazy workaround, but I'm not getting the 404/500 errors any more :) So how do I proceed? How can I see what version of go-sql-driver/mysql is in the binary? The issue go-sql-driver/mysql#556 was closed several months ago with no real solution other than either "dont forget to db.Close()" or "disable strict mode". |
This has been packaged into Gitea binary. |
the problem is very annoying |
I've set my timeouts in /etc/mysql/my.cnf to just over 10 mins and can confirm that the issue has cleared up.
This is a shared server so not an ideal solution. @lunny how can I check which version is packaged into the binary? Is it worth me trying Gitea@dev-master? @cevin are you able to try this on your cloud instance? or check the mysql logs for that timeout error? It would help confirm if we are describing the same issue. I guess you don't really have that level of access on a cloud? |
So looks like Gitea 1.8.1 is using go mysql driver V1.4. The Gitea 1.8.1 branch looks like its using driver V1.4 My testing on 1.9.0+dev-254-g710245e81 still has the issue :( So either my calculations are wrong and the fix has not been included (can anyone confirm this?) or it has not worked. Hmmm :/ |
We override the previous tag 1.4.0 with a commit dating 2018-12-18 that should contain this fix 🤔 https://github.com/go-gitea/gitea/blame/710245e81e0d65c72231dbb3b5c9f860cdc71899/go.mod#L140 |
@bobemoe yep, but I can set |
Perhaps relevant here: Which claims to fix similar problem and has more discussion/links here: |
gogs/gogs@0a176df should be good practice, we could take it. |
That should probably be set only if database is MySQL |
closed by #7071 |
Just to confirm I've tried 1.8.2 and set my mysql timeouts back to 60s. All seems to be functioning well. Looking at mysql processlist, I can see that the behaviour has changed from my previous investigation. Gitea no no longer keeps a connection open. This solves the issue for me. Thanks everyone :) Although I see no connection kept open, looking at the mysql id numbers jump up by about 10 now each time I hit a page, suggests Gitea is not reusing its mysql connections at all now and opening a new one per query? Just wanted to make sure this will not be a performance hit on busier sites? |
[x]
):Description
like #5736
Aliyun Cloud ( www.aliyun.com ) & Aliyun RDS MySQL ( www.aliyun.com/product/rds/mysql )
as far as I know aliyun rds mysql server recycle connection is very fast, so....
The text was updated successfully, but these errors were encountered: