esm: do not use 'beforeExit'
on the main thread
#47964
Merged
'beforeExit'
on the main thread
#47964