Skip to content

Commit c672628

Browse files
committed
Hotfix: Fix a race condition leading to a busy loop preventing progress in Eth1 syncing
1 parent 496d026 commit c672628

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

beacon_chain/eth1/eth1_monitor.nim

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -947,19 +947,17 @@ proc detectPrimaryProviderComingOnline(m: Eth1Monitor) {.async.} =
947947
continue
948948

949949
var tempProvider = tempProviderRes.get
950-
var testRequest = tempProvider.web3.provider.net_version()
950+
let testRequest = tempProvider.web3.provider.net_version()
951951

952-
yield testRequest
952+
yield testRequest or sleepAsync(web3Timeouts)
953953

954-
try: await tempProvider.close()
955-
except CatchableError as err:
956-
debug "Failed to close temp web3 provider", err = err.msg
954+
traceAsyncErrors tempProvider.close()
957955

958-
if testRequest.failed:
959-
await sleepAsync(checkInterval)
960-
elif m.state == Started:
956+
if testRequest.completed and m.state == Started:
961957
m.state = ReadyToRestartToPrimary
962958
return
959+
else:
960+
await sleepAsync(checkInterval)
963961

964962
proc doStop(m: Eth1Monitor) {.async.} =
965963
safeCancel m.runFut
@@ -1173,25 +1171,27 @@ func init(T: type FullBlockId, blk: Eth1BlockHeader|BlockObject): T =
11731171
FullBlockId(number: Eth1BlockNumber blk.number, hash: blk.hash)
11741172

11751173
proc startEth1Syncing(m: Eth1Monitor, delayBeforeStart: Duration) {.async.} =
1176-
if m.state in {Started, ReadyToRestartToPrimary}:
1174+
if m.state == Started:
11771175
return
11781176

11791177
let isFirstRun = m.state == Initialized
1178+
let needsReset = m.state in {Failed, ReadyToRestartToPrimary}
1179+
1180+
m.state = Started
11801181

11811182
if delayBeforeStart != ZeroDuration:
11821183
await sleepAsync(delayBeforeStart)
11831184

11841185
# If the monitor died with an exception, the web3 provider may be in
11851186
# an arbitary state, so we better reset it (not doing this has resulted
11861187
# in resource leaks historically).
1187-
if not m.dataProvider.isNil and m.state == Failed:
1188+
if not m.dataProvider.isNil and needsReset:
11881189
# We introduce a local var to eliminate the risk of scheduling two
11891190
# competing calls to `close` below.
11901191
let provider = m.dataProvider
11911192
m.dataProvider = nil
11921193
await provider.close()
11931194

1194-
m.state = Started
11951195
await m.ensureDataProvider()
11961196

11971197
# We might need to reset the chain if the new provider disagrees

0 commit comments

Comments
 (0)