From 9f6db7193796e846ca72a024d19f207041c306da Mon Sep 17 00:00:00 2001 From: Colin Sullivan Date: Tue, 15 Nov 2022 14:20:16 -0700 Subject: [PATCH] Fix concurrent map write Signed-off-by: Colin Sullivan --- server/filestore.go | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/server/filestore.go b/server/filestore.go index 9d68997c..782268c6 100644 --- a/server/filestore.go +++ b/server/filestore.go @@ -6233,6 +6233,9 @@ func (o *consumerFileStore) UpdateConfig(cfg *ConsumerConfig) error { } func (o *consumerFileStore) Update(state *ConsumerState) error { + o.mu.Lock() + defer o.mu.Unlock() + // Sanity checks. if state.AckFloor.Consumer > state.Delivered.Consumer { return fmt.Errorf("bad ack floor for consumer") @@ -6262,12 +6265,8 @@ func (o *consumerFileStore) Update(state *ConsumerState) error { } } - // Replace our state. - o.mu.Lock() - // Check to see if this is an outdated update. if state.Delivered.Consumer < o.state.Delivered.Consumer { - o.mu.Unlock() return fmt.Errorf("old update ignored") } @@ -6276,7 +6275,6 @@ func (o *consumerFileStore) Update(state *ConsumerState) error { o.state.Pending = pending o.state.Redelivered = redelivered o.kickFlusher() - o.mu.Unlock() return nil }