mirror of
https://github.com/coder/coder.git
synced 2025-07-06 15:41:45 +00:00
fix: avoid race between replicas on start (#12344)
DERP mesh key setup would do a SELECT and then an INSERT on failure, without a lock. During some testing with multiple replicas, I managed to cause a replica to crash due to them initializing simultaneously. Fixes: Encountered an error running "coder server" create coder API: insert mesh key: pq: duplicate key value violates unique constraint "site_configs_key_key" Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
@ -1761,6 +1761,9 @@ func (q *FakeQuerier) GetDERPMeshKey(_ context.Context) (string, error) {
|
||||
q.mutex.RLock()
|
||||
defer q.mutex.RUnlock()
|
||||
|
||||
if q.derpMeshKey == "" {
|
||||
return "", sql.ErrNoRows
|
||||
}
|
||||
return q.derpMeshKey, nil
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user