[PR #3268] [MERGED] Fix race condition in team functions #16850

Closed
opened 2025-11-02 12:20:33 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/gitea/pull/3268
Author: @ethantkoenig
Created: 12/30/2017
Status: Merged
Merged: 12/31/2017
Merged by: @lunny

Base: masterHead: fix/team_race_cond


📝 Commits (4)

  • b819498 Fix race condition in team functions
  • 01eaecf Merge branch 'master' into fix/team_race_cond
  • 1dab5c4 Merge branch 'master' into fix/team_race_cond
  • a138623 Merge branch 'master' into fix/team_race_cond

📊 Changes

1 file changed (+6 additions, -5 deletions)

View changed files

📝 models/org_team.go (+6 -5)

📄 Description

Fix race conditions in addRepository and AddTeamMembers functions.

Previously, we incremented the NumMembers/NumRepos field of an already-loaded team, and then updated the corresponding column in the team table. This will result in a race condition if two requests are made concurrently (since in both requests, the team will be loaded before the transaction begins).

This PR instead uses the Incr(..) method, which does not depend on the fields of team which was loaded before the transaction began.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/gitea/pull/3268 **Author:** [@ethantkoenig](https://github.com/ethantkoenig) **Created:** 12/30/2017 **Status:** ✅ Merged **Merged:** 12/31/2017 **Merged by:** [@lunny](https://github.com/lunny) **Base:** `master` ← **Head:** `fix/team_race_cond` --- ### 📝 Commits (4) - [`b819498`](https://github.com/go-gitea/gitea/commit/b819498e7c718efd49e0922abde0919a95013870) Fix race condition in team functions - [`01eaecf`](https://github.com/go-gitea/gitea/commit/01eaecfcbea0efd84f494ee725bdb37a189f6d77) Merge branch 'master' into fix/team_race_cond - [`1dab5c4`](https://github.com/go-gitea/gitea/commit/1dab5c48019536a8c634688fa57f0812739fdf9f) Merge branch 'master' into fix/team_race_cond - [`a138623`](https://github.com/go-gitea/gitea/commit/a1386231be45981f66e5d1395134d96ba8eaca9e) Merge branch 'master' into fix/team_race_cond ### 📊 Changes **1 file changed** (+6 additions, -5 deletions) <details> <summary>View changed files</summary> 📝 `models/org_team.go` (+6 -5) </details> ### 📄 Description Fix race conditions in `addRepository` and `AddTeamMembers` functions. Previously, we incremented the `NumMembers`/`NumRepos` field of an already-loaded team, and then updated the corresponding column in the `team` table. This will result in a race condition if two requests are made concurrently (since in both requests, the team will be loaded before the transaction begins). This PR instead uses the `Incr(..)` method, which does not depend on the fields of team which was loaded before the transaction began. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-02 12:20:33 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#16850