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!
This commit is contained in:
Kyle Carberry
2022-04-12 15:11:57 -05:00
committed by GitHub
parent e8b310166f
commit e3458277df

View File

@ -626,7 +626,9 @@ func (q *fakeQuerier) GetWorkspaceAgentByAuthToken(_ context.Context, authToken
q.mutex.RLock()
defer q.mutex.RUnlock()
for _, agent := range q.provisionerJobAgent {
// The schema sorts this by created at, so we iterate the array backwards.
for i := len(q.provisionerJobAgent) - 1; i >= 0; i-- {
agent := q.provisionerJobAgent[i]
if agent.AuthToken.String() == authToken.String() {
return agent, nil
}