Skip to content

Commit e345827

Browse files
authored
fix: Multiple builds using the incorrect agent token (#983)
This was an issue with our in-memory database that caused newer builds to return an outdated agent, which would then be rejected. A test case has been added to ensure this can't happen again!
1 parent e8b3101 commit e345827

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

coderd/database/databasefake/databasefake.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,9 @@ func (q *fakeQuerier) GetWorkspaceAgentByAuthToken(_ context.Context, authToken
626626
q.mutex.RLock()
627627
defer q.mutex.RUnlock()
628628

629-
for _, agent := range q.provisionerJobAgent {
629+
// The schema sorts this by created at, so we iterate the array backwards.
630+
for i := len(q.provisionerJobAgent) - 1; i >= 0; i-- {
631+
agent := q.provisionerJobAgent[i]
630632
if agent.AuthToken.String() == authToken.String() {
631633
return agent, nil
632634
}

0 commit comments

Comments
 (0)