Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 24417c5

Browse files
committed
Lock before modification
Signed-off-by: Danny Kopping <[email protected]>
1 parent 4211c84 commit 24417c5

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -930,6 +930,9 @@ func (q *FakeQuerier) AcquireNotificationMessages(_ context.Context, arg databas
930930
return nil, err
931931
}
932932

933+
q.mutex.Lock()
934+
defer q.mutex.Unlock()
935+
933936
// Shift the first "Count" notifications off the slice (FIFO).
934937
sz := len(q.notificationMessages)
935938
if sz > int(arg.Count) {
@@ -939,9 +942,6 @@ func (q *FakeQuerier) AcquireNotificationMessages(_ context.Context, arg databas
939942
list := q.notificationMessages[:sz]
940943
q.notificationMessages = q.notificationMessages[sz:]
941944

942-
q.mutex.Lock()
943-
defer q.mutex.Unlock()
944-
945945
var out []database.AcquireNotificationMessagesRow
946946
for _, nm := range list {
947947
acquirableStatuses := []database.NotificationMessageStatus{database.NotificationMessageStatusPending, database.NotificationMessageStatusTemporaryFailure}

0 commit comments

Comments
 (0)