[bugfix] Lock when checking/creating notifs to avoid race (#2890)

* [bugfix] Lock when checking/creating notifs to avoid race

* test notif spam
This commit is contained in:
tobi
2024-05-02 14:43:00 +02:00
committed by GitHub
parent 725a21b027
commit ebec95a522
15 changed files with 290 additions and 133 deletions

View File

@ -38,7 +38,7 @@ type utils struct {
state *state.State
media *media.Processor
account *account.Processor
surface *surface
surface *Surface
}
// wipeStatus encapsulates common logic
@ -245,7 +245,7 @@ func (u *utils) incrementStatusesCount(
status *gtsmodel.Status,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -276,7 +276,7 @@ func (u *utils) decrementStatusesCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -310,7 +310,7 @@ func (u *utils) incrementFollowersCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -339,7 +339,7 @@ func (u *utils) decrementFollowersCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -373,7 +373,7 @@ func (u *utils) incrementFollowingCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -402,7 +402,7 @@ func (u *utils) decrementFollowingCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -436,7 +436,7 @@ func (u *utils) incrementFollowRequestsCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.
@ -465,7 +465,7 @@ func (u *utils) decrementFollowRequestsCount(
account *gtsmodel.Account,
) error {
// Lock on this account since we're changing stats.
unlock := u.state.AccountLocks.Lock(account.URI)
unlock := u.state.ProcessingLocks.Lock(account.URI)
defer unlock()
// Populate stats.