From 100a01b4b17fbf396a9e7b3ffde2733a5086d1aa Mon Sep 17 00:00:00 2001 From: tbjump Date: Wed, 3 May 2023 23:53:18 +0000 Subject: [PATCH] node/watchers/evm: fix potential resource leak due to wrong context usage (TOB-WORMGUWA-6) --- node/pkg/watchers/evm/watcher.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/node/pkg/watchers/evm/watcher.go b/node/pkg/watchers/evm/watcher.go index 0004ed8f9..b935e15bf 100644 --- a/node/pkg/watchers/evm/watcher.go +++ b/node/pkg/watchers/evm/watcher.go @@ -162,8 +162,14 @@ func NewEthWatcher( } } -func (w *Watcher) Run(ctx context.Context) error { - logger := supervisor.Logger(ctx) +func (w *Watcher) Run(parentCtx context.Context) error { + logger := supervisor.Logger(parentCtx) + + // later on we will spawn multiple go-routines through `RunWithScissors`, i.e. catching panics. + // If any of them panic, this function will return, causing this child context to be canceled + // such that the other go-routines can free up resources + ctx, watcherContextCancelFunc := context.WithCancel(parentCtx) + defer watcherContextCancelFunc() useFinalizedBlocks := ((w.chainID == vaa.ChainIDEthereum || w.chainID == vaa.ChainIDSepolia) && (!w.unsafeDevMode)) if (w.chainID == vaa.ChainIDKarura || w.chainID == vaa.ChainIDAcala) && (!w.unsafeDevMode) {