Skip to content
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

Internal error: database is locked (repo.go / serv.go) #1769

Closed
cookiengineer opened this issue May 20, 2017 · 9 comments
Closed

Internal error: database is locked (repo.go / serv.go) #1769

cookiengineer opened this issue May 20, 2017 · 9 comments
Labels

Comments

@cookiengineer
Copy link

cookiengineer commented May 20, 2017

  • Gitea version (or commit ref): 1.1.1 built with: bindata, sqlite
  • Git version: 2.13.0 on client and 2.12.2 on server
  • Operating system: Arch Linux to Arch Linux ARM
  • Database: SQLite
  • Can you reproduce the bug at https://try.gitea.io: No
  • Log gist:

Description

When trying to push sometimes gitea answers with:

[$] git push backup development -f
Gitea: Internal error
UpdatePublicKey: database is locked
error: failed to push some refs to 'git@git-mirror:Artificial-Engineering/lycheejs.git'

When checking gitea via web interface everything seemed normal, no errors shown in dashboard or admin interface.

Afterwards I restarted the gitea service (using systemctl stop gitea; systemctl start gitea) and everything seems to work nicely again.

The gitea.log file has these entries (literally hundreds of them):

2017/05/20 14:34:20 [I] Log Mode: File(Info)
2017/05/20 14:34:20 [I] XORM Log Mode: File(Info)
2017/05/20 14:34:20 [I] Cache Service Enabled
2017/05/20 14:34:20 [I] Session Service Enabled
2017/05/20 14:34:21 [I] Git Version: 2.12.2
2017/05/20 14:34:21 [I] SQLite3 Supported
2017/05/20 14:34:21 [I] Run Mode: Production
(...)
2017/05/20 14:34:21 [...gitea/models/repo.go:2042 CheckRepoStats()] [E] Update repository count 'num_watches'[2]: database table is locked: repository
(... literally dozens of times the same message ... )
2017/05/20 14:34:21 [...gitea/models/repo.go:2042 CheckRepoStats()] [E] Update repository count 'num_watches'[60]: database table is locked: repository
2017/05/20 14:34:23 [I] Listen: http://0.0.0.0:3000

The serv.log contains this entry around the same time:

2017/05/10 19:38:05 [T] No update task is presented: 7565f22d-5db4-4d34-b071-ae2b77a8fa46
2017/05/20 14:32:14 [...io/gitea/cmd/serv.go:318 runServ()] [F] UpdatePublicKey: database is locked
2017/05/20 14:32:48 [...io/gitea/cmd/serv.go:318 runServ()] [F] UpdatePublicKey: database is locked

The xorm.log file looks pretty normal, no errors, just some SQL queries and everything looks like when it worked afterwards.

I thought I report this bug anyways, because I'm unsure whether something really painful can happen in future in case this happens again.

@lunny lunny added the type/bug label May 21, 2017
@lunny lunny added this to the 1.x.x milestone May 21, 2017
@typeless
Copy link
Contributor

Complementary information:

https://gist.github.com/mrnugget/0eda3b2b53a70fa4a894

@bkcsoft
Copy link
Member

bkcsoft commented Jun 15, 2017

Could you test if this fixes the issue? #1961 (applying the diff and building on v1.1.2 should be straight forward)

@typeless
Copy link
Contributor

@bkcsoft This bug is hard to reproduce. My Gitea server has only got one per month since April. There were 10 cases in March though. Of course, the numbers have something to do with the variations of the user activities as well.

It would be nice if there is a test that can reliably trigger the problem.

@cookiengineer
Copy link
Author

@bkcsoft: Same for me, I cannot reliably trigger this problem. It's pretty random when it happens, though I suspect that in my case it's related to turning off the Raspberry Pi's power while it has a job/process running.

@bkcsoft
Copy link
Member

bkcsoft commented Jun 17, 2017

One way of triggering it could be to have 10 users create PRs to the same repo at the same time.

@typeless
Copy link
Contributor

typeless commented Jun 20, 2017

I think we should have the xorm library protect the db connection with a lock for SQLite. SQLite doesn't provide out-of-box multithreading safety for shared-single-connection-over-shared-cache scenario, which is how it is configured in Gitea. Otherwise Gitea would probably need to initiate a connection for every goroutine.

P.S. The 'database table is locked' error can be reproduced, quite reliably, by our integration tests already.

@lafriks
Copy link
Member

lafriks commented Jun 20, 2017

I agree that xorm library should protect sqlite connection from multiple threads

@lunny
Copy link
Member

lunny commented Jun 20, 2017

@typeless @lafriks you are welcome to open issue or send PR to xorm to do that.

@lunny
Copy link
Member

lunny commented Jun 23, 2017

continue via #2040

@lunny lunny closed this as completed Jun 23, 2017
@lunny lunny removed this from the 1.x.x milestone Jun 23, 2017
@go-gitea go-gitea locked and limited conversation to collaborators Nov 23, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

5 participants