node/watchers/evm: fix potential resource leak due to wrong context usage (TOB-WORMGUWA-6)

This commit is contained in:
tbjump 2023-05-03 23:53:18 +00:00 committed by tbjump
parent f60a5c81cc
commit 100a01b4b1
1 changed files with 8 additions and 2 deletions

View File

@ -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) {