From 5ac40f1bf58b5287d4701060cccfcc48a59ce322 Mon Sep 17 00:00:00 2001 From: Urvi Date: Thu, 1 Jun 2023 11:28:15 -0700 Subject: [PATCH] Protect 'currentState' variable using Mutex to prevent race condition. --- services/horizon/internal/ingest/main.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/services/horizon/internal/ingest/main.go b/services/horizon/internal/ingest/main.go index ab4184202f..dc6dc8dd46 100644 --- a/services/horizon/internal/ingest/main.go +++ b/services/horizon/internal/ingest/main.go @@ -230,7 +230,8 @@ type system struct { reapOffsets map[string]int64 - currentState State + currentStateMutex sync.Mutex + currentState State } func NewSystem(config Config) (System, error) { @@ -484,6 +485,8 @@ func (s *system) initMetrics() { } func (s *system) GetCurrentState() State { + s.currentStateMutex.Lock() + defer s.currentStateMutex.Unlock() return s.currentState } @@ -652,7 +655,10 @@ func (s *system) runStateMachine(cur stateMachineNode) error { panic("unexpected transaction") } + s.currentStateMutex.Lock() s.currentState = cur.GetState() + s.currentStateMutex.Unlock() + next, err := cur.run(s) if err != nil { logger := log.WithFields(logpkg.F{