Skip to content

fix: avoid database deadlock in GetParticipantsByIssueID() - #8395

Open
crd477 wants to merge 1 commit into
gogs:mainfrom
crd477:fix/issue-8375
Open

fix: avoid database deadlock in GetParticipantsByIssueID()#8395
crd477 wants to merge 1 commit into
gogs:mainfrom
crd477:fix/issue-8375

Conversation

@crd477

@crd477 crd477 commented Jul 22, 2026

Copy link
Copy Markdown

Describe the pull request

Fix a database deadlock in GetParticipantsByIssueID().
Change mailParticipants() to pass Engine e
into mailIssueCommentToParticipants() and subsequently GetParticipantsByIssueID(). This allows GetParticipantsByIssueID() to use the session created in CreateComment() to issue the database query, avoiding a deadlock.

This is a patch for #8375, and was authored by @chuckcranor

Checklist

  • I agree to follow the Code of Conduct by submitting this pull request.
  • I have read and acknowledge the Contributing guide.
  • I have added test cases to cover the new code or have provided the test plan. (if applicable)
  • I have added an entry to CHANGELOG. (if applicable)

Test plan

  1. Create a new gogs instance using the SQLite 3 database.
  2. Enable ENABLE_EMAIL_NOTIFICATION by setting:
[user]
ENABLE_EMAIL_NOTIFICATION = true
  1. Attempt to comment on an issue in a repository.
  2. Confirm that the server does not hang, the comment is successfully recorded and displayed, and that email notification is received by watchers and participants.

Change `mailParticipants()` to pass Engine `e`
into `mailIssueCommentToParticipants()` and subsequently
`GetParticipantsByIssueID()`.  This allows `GetParticipantsByIssueID()` to
use the session created in `CreateComment()` to issue the database query,
avoiding a deadlock.

This is a patch for gogs#8375, and was authored by @chuckcranor

Signed-off-by: Chad Dougherty <crd477@icloud.com>
@crd477
crd477 requested a review from unknwon as a code owner July 22, 2026 16:04
@crd477 crd477 changed the title fix database deadlock in GetParticipantsByIssueID() fix: avoid database deadlock in GetParticipantsByIssueID() Jul 23, 2026
@unknwon
unknwon requested a balanced review from Copilot August 7, 2026 12:31

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Prevents SQLite deadlocks when notifying issue participants by reusing the active comment transaction.

Changes:

  • Passes the active database engine through mail notification functions.
  • Queries participants using that engine.
  • Documents the fix in the changelog.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
internal/database/issue.go Uses the provided engine for participant queries.
internal/database/issue_mail.go Propagates the engine through notification handling.
internal/database/comment.go Passes the active comment session to notifications.
CHANGELOG.md Adds the fix entry.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread CHANGELOG.md

### Fixed

- Fix database deadlock in mail notifications for comments. [#8375](https://github.com/gogs/gogs/issues/8375)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants