mirror of
				https://github.com/superseriousbusiness/gotosocial
				synced 2025-06-05 21:59:39 +02:00 
			
		
		
		
	[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:
		@@ -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.
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user