Batch calling of updateIssuesMeta causes database deadlock #8037

Closed
opened 2025-11-02 07:51:54 -06:00 by GiteaMirror · 8 comments
Owner

Originally created by @wxiaoguang on GitHub (Oct 28, 2021).

Gitea Version

dev(main)

Description

Bug:

141d1a2aa5/web_src/js/features/repo-legacy.js (L87-L91)

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
Originally created by @wxiaoguang on GitHub (Oct 28, 2021). ### Gitea Version dev(main) ### Description Bug: https://github.com/go-gitea/gitea/blob/141d1a2aa5ff31267661c1985f52e6c02eafea11/web_src/js/features/repo-legacy.js#L87-L91 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 ```
GiteaMirror added the topic/uiissue/confirmedtype/bug labels 2025-11-02 07:51:54 -06:00
Author
Owner

@wxiaoguang commented on GitHub (Oct 28, 2021):

Blocked by

I do not want to make huge conflicts between PRs.

@wxiaoguang commented on GitHub (Oct 28, 2021): Blocked by * https://github.com/go-gitea/gitea/pull/17386 I do not want to make huge conflicts between PRs.
Author
Owner

@lunny commented on GitHub (Oct 28, 2021):

It seems it's also a backend bug.

@lunny commented on GitHub (Oct 28, 2021): It seems it's also a backend bug.
Author
Owner

@wxiaoguang commented on GitHub (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.

@wxiaoguang commented on GitHub (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.
Author
Owner

@zeripath commented on GitHub (Oct 28, 2021):

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

@zeripath commented on GitHub (Oct 28, 2021): The db should never deadlock - this is a backend bug.
Author
Owner

@wxiaoguang commented on GitHub (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).

@wxiaoguang commented on GitHub (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).
Author
Owner

@lunny commented on GitHub (Nov 15, 2021):

Is this resolved?

@lunny commented on GitHub (Nov 15, 2021): Is this resolved?
Author
Owner

@wxiaoguang commented on GitHub (Nov 15, 2021):

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

@wxiaoguang commented on GitHub (Nov 15, 2021): Not yet, I haven't got time for this. (If someone can help that's also very welcome)
Author
Owner

@wxiaoguang commented on GitHub (Nov 15, 2021):

I proposed a simple fix, please review.

@wxiaoguang commented on GitHub (Nov 15, 2021): I proposed a simple fix, please review.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#8037