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

Gitea lockup on adopting repository with sqlite #33561

Closed
TheFox0x7 opened this issue Feb 11, 2025 · 4 comments
Closed

Gitea lockup on adopting repository with sqlite #33561

TheFox0x7 opened this issue Feb 11, 2025 · 4 comments
Labels
Milestone

Comments

@TheFox0x7
Copy link
Contributor

Description

If someone tries to adopt a repository on their instance that has a large amount of tags (tested on linux repository) the entire instance hangs.

Reproduction steps:

  1. Configure gitea with sqlite
  2. Copy a repository to any user directory where it can be adopted
  3. Adopt the repository
  4. Try to access any gitea page with browser or curl an endpoint which requires a database query - /explore/repos seems to work as demo

Expected behavior:
Gitea returns a page for visitor as normal and continues to adopt the repository

Actual behavior:
Entire instance doesn't respond to any requests except those which don't need database query - curl on homepage for anonymous user works but /explore/repos endpoint doesn't.

It does not happen with postgres, so I think it's sqlite specific - probably something to do with the entire thing being in transaction but I'm speculating at this point as I don't know enough about that area.

This does not happen with regular repository migration.

gitea-diagnosis-20250211-173242.zip

Gitea Version

1.23.3

Can you reproduce the bug on the Gitea demo site?

No

Log Gist

No response

Screenshots

No response

Git Version

No response

Operating System

linux

How are you running Gitea?

selfbuild, reproduced in container.

Database

SQLite

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 12, 2025

The dump shows that the "adopt" operation is still running (and its sqlite transaction lock is still hold)

1 @ 0x479a6e 0x40d99c 0x40d552 0x82a14b 0x482041
# labels: {"graceful_lifecycle":"with-hammer", "pid":"67ab89bd", "ppid":"", "process_description":"HTTP: POST /-/admin/repos/unadopted", "process_type":"request"}
#	0x82a14a	database/sql.(*Tx).awaitDone+0x2a	/usr/local/go/src/database/sql/sql.go:2204

1 @ 0x479a6e 0x40d99c 0x40d552 0xedef8c 0x482041
# labels: {"graceful_lifecycle":"with-hammer", "pid":"67ab89bd", "ppid":"", "process_description":"HTTP: POST /-/admin/repos/unadopted", "process_type":"request"}
#	0xedef8b	code.gitea.io/gitea/modules/git.catFileBatchCheck.func2+0x2b	/go/src/code.gitea.io/gitea/modules/git/batch_reader.go:58

1 @ 0x479a6e 0x40d99c 0x40d552 0xedfbac 0x482041
# labels: {"graceful_lifecycle":"with-hammer", "pid":"67ab89bd", "ppid":"", "process_description":"HTTP: POST /-/admin/repos/unadopted", "process_type":"request"}
#	0xedfbab	code.gitea.io/gitea/modules/git.catFileBatch.func2+0x2b	/go/src/code.gitea.io/gitea/modules/git/batch_reader.go:106

1 @ 0x479a6e 0x43b837 0x478d65 0x4c4587 0x4c587a 0x4c5868 0x5c3845 0x5d4185 0x97a5d7 0x482041
# labels: {"graceful_lifecycle":"with-hammer", "pid":"67ab89bd", "ppid":"", "process_description":"HTTP: POST /-/admin/repos/unadopted", "process_type":"request"}
#	0x478d64	internal/poll.runtime_pollWait+0x84		/usr/local/go/src/runtime/netpoll.go:351
#	0x4c4586	internal/poll.(*pollDesc).wait+0x26		/usr/local/go/src/internal/poll/fd_poll_runtime.go:84
#	0x4c5879	internal/poll.(*pollDesc).waitRead+0x279	/usr/local/go/src/internal/poll/fd_poll_runtime.go:89
#	0x4c5867	internal/poll.(*FD).Read+0x267			/usr/local/go/src/internal/poll/fd_unix.go:165
#	0x5c3844	net.(*netFD).Read+0x24				/usr/local/go/src/net/fd_posix.go:55
#	0x5d4184	net.(*conn).Read+0x44				/usr/local/go/src/net/net.go:189
#	0x97a5d6	net/http.(*connReader).backgroundRead+0x36	/usr/local/go/src/net/http/server.go:690


# labels: {"graceful_lifecycle":"with-hammer", "pid":"67ab89d8", "ppid":"67ab89bd", "process_description":"git.Run(by:git.CommitsCount, repo:.../admin/linux2.git): /usr/bin/git ...global... rev-list --count ffd294d346d185b70e28b1a28abe367bbfe53c04", "process_type":"normal"}
#	0x49c9f8	syscall.Syscall6+0x38														/usr/local/go/src/syscall/syscall_linux.go:95
#	0x4d58b5	os.(*Process).pidfdWait+0x235													/usr/local/go/src/os/pidfd_linux.go:110
#	0x4d0cc4	os.(*Process).wait+0x24														/usr/local/go/src/os/exec_unix.go:27
#	0x7d1f44	os.(*Process).Wait+0x44														/usr/local/go/src/os/exec.go:358
#	0x7d1f3c	os/exec.(*Cmd).Wait+0x3c													/usr/local/go/src/os/exec/exec.go:906
#	0xee5889	code.gitea.io/gitea/modules/git.(*Command).run+0x789										/go/src/code.gitea.io/gitea/modules/git/command.go:352
#	0xee624a	code.gitea.io/gitea/modules/git.(*Command).runStdBytes+0x16a									/go/src/code.gitea.io/gitea/modules/git/command.go:452
#	0xee5f16	code.gitea.io/gitea/modules/git.(*Command).RunStdString+0x16									/go/src/code.gitea.io/gitea/modules/git/command.go:414
#	0xee75ea	code.gitea.io/gitea/modules/git.CommitsCount+0x70a										/go/src/code.gitea.io/gitea/modules/git/commit.go:185
#	0xee77b7	code.gitea.io/gitea/modules/git.(*Commit).CommitsCount+0x117									/go/src/code.gitea.io/gitea/modules/git/commit.go:195
#	0x1ceb6c9	code.gitea.io/gitea/modules/repository.PushUpdateAddTag+0x269									/go/src/code.gitea.io/gitea/modules/repository/repo.go:153
#	0x1ceb2b1	code.gitea.io/gitea/modules/repository.SyncReleasesWithTags.func1+0x1f1								/go/src/code.gitea.io/gitea/modules/repository/repo.go:112
#	0xf1327d	code.gitea.io/gitea/modules/git.WalkShowRef+0x57d										/go/src/code.gitea.io/gitea/modules/git/repo_branch_nogogit.go:170
#	0xf129e4	code.gitea.io/gitea/modules/git.(*Repository).WalkReferences+0x144								/go/src/code.gitea.io/gitea/modules/git/repo_branch_nogogit.go:87
#	0x1ceaba4	code.gitea.io/gitea/modules/repository.SyncReleasesWithTags+0x2e4								/go/src/code.gitea.io/gitea/modules/repository/repo.go:106
#	0x21a738e	code.gitea.io/gitea/services/repository.adoptRepository+0x52e									/go/src/code.gitea.io/gitea/services/repository/adopt.go:152
#	0x21a67a4	code.gitea.io/gitea/services/repository.AdoptRepository.func1+0x1c4								/go/src/code.gitea.io/gitea/services/repository/adopt.go:79
#	0x108c49e	code.gitea.io/gitea/models/db.txWithNoCheck+0xde										/go/src/code.gitea.io/gitea/models/db/context.go:188
#	0x108c37c	code.gitea.io/gitea/models/db.WithTx+0xdc											/go/src/code.gitea.io/gitea/models/db/context.go:178
#	0x21a64e4	code.gitea.io/gitea/services/repository.AdoptRepository+0x244									/go/src/code.gitea.io/gitea/services/repository/adopt.go:55
#	0x2ba6ae4	code.gitea.io/gitea/routers/web/admin.AdoptOrDeleteRepository+0x384								/go/src/code.gitea.io/gitea/routers/web/admin/repos.go:145

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Feb 12, 2025

selfbuild, reproduced in container.

What are the build tags? IIRC using sqlite_unlock_notify or not might also affect the lock behavior.

And maybe we should optimize the "adopt" code, to separate the db context and git context to avoid the long-running git command holds the lock.

@TheFox0x7
Copy link
Contributor Author

it's the standard set of tags: sqlite sqlite_unlock_notify bindata
And yeah, that would most likely fix it. I don't know how to approach it, otherwise I'd submit a PR.

@wxiaoguang
Copy link
Contributor

Maybe something like this: #33566 (I haven't really tested it, feel free to try it)

@lunny lunny closed this as completed in e741448 Feb 12, 2025
@lunny lunny added this to the 1.23.4 milestone Feb 12, 2025
GiteaBot pushed a commit to GiteaBot/gitea that referenced this issue Feb 12, 2025
…, fuzzy prompt, mirror proxy, adopt git) (go-gitea#33569)

* Make artifact list output a stable order
* Fix go-gitea#33506
* Fix go-gitea#33521
* Fix go-gitea#33288
* Fix go-gitea#33196
* Fix go-gitea#33561
lunny pushed a commit that referenced this issue Feb 12, 2025
…, fuzzy prompt, mirror proxy, adopt git) (#33569) (#33577)

Backport #33569 by @wxiaoguang

* Make artifact list output has stable order
* Fix #33506
* Fix #33521
* Fix #33288
* Fix #33196
* Fix #33561

Co-authored-by: wxiaoguang <wxiaoguang@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants