mirror of
https://github.com/go-gitea/gitea.git
synced 2026-03-15 12:42:02 -05:00
About DB connection random lost #3269
Closed
opened 2025-11-02 05:06:05 -06:00 by GiteaMirror
·
19 comments
No Branch/Tag Specified
main
release/v1.25
release/v1.24
release/v1.23
release/v1.22
release/v1.21
release/v1.20
release/v1.19
release/v1.18
release/v1.17
release/v1.16
release/v1.15
release/v1.14
release/v1.13
release/v1.12
release/v1.11
release/v1.10
release/v1.9
release/v1.8
v1.25.3
v1.25.2
v1.25.1
v1.25.0
v1.24.7
v1.25.0-rc0
v1.26.0-dev
v1.24.6
v1.24.5
v1.24.4
v1.24.3
v1.24.2
v1.24.1
v1.24.0
v1.23.8
v1.24.0-rc0
v1.25.0-dev
v1.23.7
v1.23.6
v1.23.5
v1.23.4
v1.23.3
v1.23.2
v1.23.1
v1.23.0
v1.23.0-rc0
v1.24.0-dev
v1.22.6
v1.22.5
v1.22.4
v1.22.3
v1.22.2
v1.22.1
v1.22.0
v1.23.0-dev
v1.22.0-rc1
v1.21.11
v1.22.0-rc0
v1.21.10
v1.21.9
v1.21.8
v1.21.7
v1.21.6
v1.21.5
v1.21.4
v1.21.3
v1.21.2
v1.20.6
v1.21.1
v1.21.0
v1.21.0-rc2
v1.21.0-rc1
v1.20.5
v1.22.0-dev
v1.21.0-rc0
v1.20.4
v1.20.3
v1.20.2
v1.20.1
v1.20.0
v1.19.4
v1.21.0-dev
v1.20.0-rc2
v1.20.0-rc1
v1.20.0-rc0
v1.19.3
v1.19.2
v1.19.1
v1.19.0
v1.19.0-rc1
v1.20.0-dev
v1.19.0-rc0
v1.18.5
v1.18.4
v1.18.3
v1.18.2
v1.18.1
v1.18.0
v1.17.4
v1.18.0-rc1
v1.19.0-dev
v1.18.0-rc0
v1.17.3
v1.17.2
v1.17.1
v1.17.0
v1.17.0-rc2
v1.16.9
v1.17.0-rc1
v1.18.0-dev
v1.16.8
v1.16.7
v1.16.6
v1.16.5
v1.16.4
v1.16.3
v1.16.2
v1.16.1
v1.16.0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3.2
v1.3.1
v1.3.0
v1.3.0-rc2
v1.3.0-rc1
v1.2.3
v1.2.2
v1.2.1
v1.2.0
v1.2.0-rc3
v1.2.0-rc2
v1.1.4
v1.2.0-rc1
v1.1.3
v1.1.2
v1.1.1
v1.1.0
v1.0.2
v1.0.1
v1.0.0
v0.9.99
Labels
Clear labels
$20
$250
$50
$500
backport/done
💎 Bounty
docs-update-needed
good first issue
hacktoberfest
issue/bounty
issue/confirmed
issue/critical
issue/duplicate
issue/needs-feedback
issue/not-a-bug
issue/regression
issue/stale
issue/workaround
lgtm/need 2
modifies/api
modifies/translation
outdated/backport/v1.18
outdated/theme/markdown
outdated/theme/timetracker
performance/bigrepo
performance/cpu
performance/memory
performance/speed
pr/breaking
proposal/accepted
proposal/rejected
pr/wip
pull-request
reviewed/wontfix
💰 Rewarded
skip-changelog
status/blocked
topic/accessibility
topic/api
topic/authentication
topic/build
topic/code-linting
topic/commit-signing
topic/content-rendering
topic/deployment
topic/distribution
topic/federation
topic/gitea-actions
topic/issues
topic/lfs
topic/mobile
topic/moderation
topic/packages
topic/pr
topic/projects
topic/repo
topic/repo-migration
topic/security
topic/theme
topic/ui
topic/ui-interaction
topic/ux
topic/webhooks
topic/wiki
type/bug
type/deprecation
type/docs
type/enhancement
type/feature
type/miscellaneous
type/proposal
type/question
type/refactoring
type/summary
type/testing
type/upstream
Mirrored from GitHub Pull Request
No Label
type/bug
Milestone
No items
No Milestone
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: github-starred/gitea#3269
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @cevin on GitHub (Apr 30, 2019).
[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....
@bobemoe commented on GitHub (May 13, 2019):
I'm getting the same kinds of errors:
==> /home/gitea/log/gitea.log <==
2019/05/13 19:41:15 [...s/context/context.go:238 func1()] [E] GetUserById: invalid connection
2019/05/13 19:41:15 [...ules/context/repo.go:299 func1()] [E] GetUserByName: invalid connection
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
mysql Ver 14.14 Distrib 5.6.43, for Linux (x86_64) using EditLine wrapper
PHP 7.3.5-1+0
20190503093827.38+stretch1.gbp60a41b (cli) (built: May 3 2019 09:38:28) ( NTSNot seeing anything in MySQL log, but maybe I haven't enabled it verbose enough.
Seeing similar reports in #5736 and #5612
@lunny commented on GitHub (May 14, 2019):
I think this should be a go-sql-driver/mysql 's problem.
@bobemoe commented on GitHub (May 14, 2019):
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?
@bobemoe commented on GitHub (May 14, 2019):
I've upgraded MySQL to 5.7.26 and still experiencing this.
The error in mysql.log is
2019-05-14T16:13:22.312637Z 3045 [Note] Aborted connection 3045 to db: 'gitea' user: 'gitea' host: 'localhost' (Got timeout reading communication packets)
@lafriks commented on GitHub (May 14, 2019):
Could it be that xorm does not close connection at same cases (https://github.com/go-sql-driver/mysql/issues/556)?
@bobemoe commented on GitHub (May 14, 2019):
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?
@lafriks commented on GitHub (May 14, 2019):
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
@bobemoe commented on GitHub (May 14, 2019):
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.
2019/05/14 20:25:13 [I] [SQL] SELECT `id`, `repo_id`, `interval`, `enable_prune`, `updated_unix`, `next_update_unix` FROM `mirror` WHERE (next_update_unix<=?) AND (next_update_unix!=0) []interface {}{1557861913}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".
@lunny commented on GitHub (May 15, 2019):
This has been packaged into Gitea binary.
@cevin commented on GitHub (May 15, 2019):
the problem is very annoying
@bobemoe commented on GitHub (May 15, 2019):
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?
@bobemoe commented on GitHub (May 15, 2019):
So looks like Gitea 1.8.1 is using go mysql driver V1.4.
V1.4.1 is out now (2018-11-14) with a potential fix:
https://github.com/go-sql-driver/mysql/blob/v1.4.1/CHANGELOG.md
https://github.com/go-sql-driver/mysql/issues/836 (committed Oct 1, 2018 )
The Gitea 1.8.1 branch looks like its using driver V1.4
The Gitea 1.9.0+dev-254-g710245e81 branch looks like its using driver c45f530f8e7fe40f4687eaa50d0c8c5f1b66f9e0 which was committed Dec 18, 2018 so should include that fix??
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 :/
@sapk commented on GitHub (May 15, 2019):
We override the previous tag 1.4.0 with a commit dating 2018-12-18 that should contain this fix 🤔
710245e81e/go.mod (L140)@cevin commented on GitHub (May 16, 2019):
@bobemoe yep, but I can set
wait_timeout & interactive_timeoutin rds( aliyun mysql cloud database) online dashboard. but looks that's not a good idea ?@mrsdizzie commented on GitHub (May 17, 2019):
Perhaps relevant here:
0a176df6fbWhich claims to fix similar problem and has more discussion/links here:
https://github.com/gogs/gogs/issues/5532
@lunny commented on GitHub (May 18, 2019):
gogs/gogs@0a176df should be good practice, we could take it.
@lafriks commented on GitHub (May 24, 2019):
That should probably be set only if database is MySQL
@lunny commented on GitHub (May 29, 2019):
closed by #7071
@bobemoe commented on GitHub (Jun 9, 2019):
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?