Skip to content

Commit

Permalink
fix: update routes under lock (#3141)
Browse files Browse the repository at this point in the history
  • Loading branch information
stuartwdouglas authored Oct 16, 2024
1 parent 6546b1e commit 8dbe738
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion backend/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,8 @@ type Service struct {
clients *ttlcache.Cache[string, clients]

// Complete schema synchronised from the database.
schemaState atomic.Value[schemaState]
schemaState atomic.Value[schemaState]
schemaSyncLock sync.Mutex

config Config

Expand Down Expand Up @@ -1802,6 +1803,8 @@ func (s *Service) getDeploymentLogger(ctx context.Context, deploymentKey model.D
// We do this in a single function so the routing table and schema are always consistent
// And they both need the same info from the DB
func (s *Service) syncRoutesAndSchema(ctx context.Context) (ret time.Duration, err error) {
s.schemaSyncLock.Lock() // This can result in confusing log messages if it is called concurrently
defer s.schemaSyncLock.Unlock()
deployments, err := s.dal.GetActiveDeployments(ctx)
if errors.Is(err, libdal.ErrNotFound) {
deployments = []dalmodel.Deployment{}
Expand Down

0 comments on commit 8dbe738

Please sign in to comment.