databroker: fix in-memory backend deadlock (#3300)

This commit is contained in:
Caleb Doxsey 2022-04-27 19:33:29 +00:00 committed by GitHub
parent f73c5c615f
commit 2e1366c417
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 18 deletions

View file

@ -188,6 +188,10 @@ func (backend *Backend) Lease(_ context.Context, leaseName, leaseID string, ttl
// Put puts a record into the in-memory store.
func (backend *Backend) Put(ctx context.Context, records []*databroker.Record) (serverVersion uint64, err error) {
backend.mu.Lock()
defer backend.mu.Unlock()
defer backend.onChange.Broadcast(ctx)
recordTypes := map[string]struct{}{}
for _, record := range records {
if record == nil {
@ -200,10 +204,6 @@ func (backend *Backend) Put(ctx context.Context, records []*databroker.Record) (
Str("db_type", record.Type)
})
backend.mu.Lock()
defer backend.mu.Unlock()
defer backend.onChange.Broadcast(ctx)
backend.recordChange(record)
c, ok := backend.lookup[record.GetType()]