gitforge/modules
Mathieu Fenniak 9e07bb07be fix: reduce deadlocks merging PRs w/ async label stat recalcs (#9868)
The intent of this change is to reduce the scope of deadlock issues identified in #9785.  I've identified other deadlock issues from synthetic testing, so this is not a complete fix, but it's a partial fix.  This design was discussed in #9785 and this is the most basic implementation, with a very small scope of work converted to use it.

Introduces a new `forgejo.org/services/stats` module which allows for the queuing and routing of recalc requests for object stats; in this case, the "number of issues" that are assigned to a label, and the number of closed issues that are assigned to a label.

The reasons that these calculations are performed asynchronously through a queue are:
- User operations that are common and performance-sensitive don't have to wait for recalculations that don't need to be exactly up-to-date at all times.  For example, merging a pull request will be a faster operation; as it closes an issue, it needs to recalculate `label.num_closed_issues` for every label attached to the PR.

- Database deadlocks that can occur between concurrent operations -- for example, if you were holding a lock on an issue while recalculating a label's count of open issues -- can be broken by making the recalculation occur outside of the transaction.

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for Go changes...
  - [x] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [x] I did not document these changes and I do not expect someone else to do it.
    - Internal developer documentation is present.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [ ] I want the title to show in the release notes with a link to this pull request.
- [x] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/9868
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Mathieu Fenniak <mathieu@fenniak.net>
Co-committed-by: Mathieu Fenniak <mathieu@fenniak.net>
2025-10-31 02:12:36 +01:00
..
actions don't execute workflows when event parsing fails; create a pre-execution error instead 2025-10-04 18:47:57 -06:00
activitypub fix: assorted ActivityPub code only refactors (#8708) 2025-07-28 15:17:29 +02:00
analyze
assetfs
auth
avatar feat: strip EXIF information from uploaded avatars (#9638) 2025-10-13 23:16:17 +02:00
base
cache
card
charset
container chore: add new functions to container.Set 2025-10-14 14:40:49 -06:00
csv
emoji
eventsource
forgefed Sent user activities to distant federated server (#8792) 2025-08-06 16:16:13 +02:00
generate
git feat: include non-conventional headers in payload for git signatures (#9558) 2025-10-14 02:18:01 +02:00
gitrepo
graceful feat: enable H2C for the HTTP server (#8861) 2025-08-16 21:00:20 +02:00
hcaptcha
highlight
hostmatcher
html
httpcache
httplib
indexer Update module github.com/meilisearch/meilisearch-go to v0.34.0 (forgejo) (#9275) 2025-09-14 13:22:15 +02:00
issue/template chore: replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3 (#8956) 2025-08-20 15:31:12 +02:00
json
keying feat: migrate action secrets to keying to store them more securely (#8692) 2025-07-29 01:03:36 +02:00
label chore: replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3 (#8956) 2025-08-20 15:31:12 +02:00
lfs chore: add unit test for SearchPointerBlobs 2025-10-03 14:37:24 +02:00
log feat(log): better parseable and configurable ssh-logs (#9056) 2025-09-11 18:59:24 +02:00
markup fix: use scrollHeight for rendered iframe if offsetHeight is unavailable (#9508) 2025-10-16 15:51:57 +02:00
mcaptcha
metrics
migration chore: replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3 (#8956) 2025-08-20 15:31:12 +02:00
nosql
optional chore: replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3 (#8956) 2025-08-20 15:31:12 +02:00
options
packages chore: replace gopkg.in/yaml.v3 with go.yaml.in/yaml/v3 (#8956) 2025-08-20 15:31:12 +02:00
paginator
pprof
private feat(log): better parseable and configurable ssh-logs (#9056) 2025-09-11 18:59:24 +02:00
process
proxy
proxyprotocol
public
queue fix: reduce deadlocks merging PRs w/ async label stat recalcs (#9868) 2025-10-31 02:12:36 +01:00
recaptcha
references
regexplru
repository
secret
session
setting feat: replace cross origin protection (#9830) 2025-10-29 22:43:22 +01:00
sitemap
ssh feat(log): better parseable and configurable ssh-logs (#9056) 2025-09-11 18:59:24 +02:00
storage fix: minio initialization can freeze indefinitely if misconfigured (#8897) 2025-08-15 21:03:51 +02:00
structs feat: Add support for administrators to set email visibility on user accounts (#9668) 2025-10-15 03:21:15 +02:00
svg
sync
system
templates chore: remove not working PREFERRED_TIMESTAMP_TENSE setting (#9490) 2025-10-01 15:16:01 +02:00
test
testlogger
timeutil
translation frontend: generic lazy loader for webcomponents (#8510) 2025-07-23 04:10:50 +02:00
turnstile
typesniffer
updatechecker
uri
user
util feat: replace cross origin protection (#9830) 2025-10-29 22:43:22 +01:00
validation chore: add email blocklist unit test 2025-08-30 09:45:19 +02:00
web
webhook
zstd