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

Batch calling of updateIssuesMeta causes database deadlock #17469

Closed
wxiaoguang opened this issue Oct 28, 2021 · 8 comments · Fixed by #17649 or #17665
Closed

Batch calling of updateIssuesMeta causes database deadlock #17469

wxiaoguang opened this issue Oct 28, 2021 · 8 comments · Fixed by #17649 or #17665
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI type/bug

Comments

@wxiaoguang
Copy link
Contributor

wxiaoguang commented Oct 28, 2021

Gitea Version

dev(main)

Description

Bug:

const promises = [];
Object.keys(items).forEach((elementId) => {
const item = items[elementId];
const promise = updateIssuesMeta(
item['update-url'],

It causes database deadlock and results in error response (some data can not be updated correctly, and the page can not be reloaded)

2021/10/28 17:51:22 .../repo/issue_label.go:209:UpdateIssueLabel() [E] RemoveLabel: Error 1213: Deadlock found when trying to get lock; try restarting transaction
2021/10/28 17:51:23 Completed POST /root/test/issues/labels 500 Internal Server Error in 421.528354ms
@wxiaoguang wxiaoguang added type/bug topic/ui Change the appearance of the Gitea UI issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented labels Oct 28, 2021
@wxiaoguang
Copy link
Contributor Author

Blocked by

I do not want to make huge conflicts between PRs.

@lunny
Copy link
Member

lunny commented Oct 28, 2021

It seems it's also a backend bug.

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Oct 28, 2021

The bug is mostly related to frontend, the concurrency API calls are incorrect.

For backend, not that related, the only thing it can do is wrapping the deadlock error and returning a friendly error response. The deadlocks can not be fully avoided in normal cases.

@zeripath
Copy link
Contributor

The db should never deadlock - this is a backend bug.

@wxiaoguang
Copy link
Contributor Author

wxiaoguang commented Oct 28, 2021

The db should never deadlock - this is a backend bug.

If two users update the same records at the same time with transactions, the database may report a dead lock. It is a correct database behavior.

Database deadlock is not the same as code deadlock. If you need more information, I can explain more.

For this problem (deadlock in UpdateIssueLabel), it's difficult to make a lock-safe transaction, because the logic is pretty complicated, many inserts and updates. However, if we can make the frontend send the updated labels in one request, then there will be no dead lock problem for most cases, except two users are updating the same issue at the same time (in such case, reporting an error to end user is also a good choice to prevent they overwrite other's labels).

@lunny
Copy link
Member

lunny commented Nov 15, 2021

Is this resolved?

@wxiaoguang
Copy link
Contributor Author

Not yet, I haven't got time for this. (If someone can help that's also very welcome)

@wxiaoguang
Copy link
Contributor Author

I proposed a simple fix, please review.

@wxiaoguang wxiaoguang linked a pull request Nov 16, 2021 that will close this issue
@go-gitea go-gitea locked and limited conversation to collaborators Apr 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
issue/confirmed Issue has been reviewed and confirmed to be present or accepted to be implemented topic/ui Change the appearance of the Gitea UI type/bug
Projects
None yet
3 participants