fix: properly tear down partially initialized executors #2348
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Refactor execution timeout logic to fix a problem where the execution worker would not be torn down correctly when failing to initialize. This PR also moves the entire initialization timeout logic to the
AbstractExecutionService
, simplifying theSnapController
. Moving the timeout logic fixes problems where job initialization was not cancelled properly resulting in "Snap is already being executed", since execution of the async functions insideAbstractExecutionService
would continue even after the timeout.The ExecutionService gets an optional
maxInitTime
constructor argument that can be set to define init time for the specific service. This timeout value is spread between initiating the execution job and running the first execution of the Snap. If the execution environment fails to initiate we attempt to tear it down in case it has partially started (this is at least the case for iframes). We make sure that the timeout is applied toinitEnvStream
which has the smallest possible footprint and worry for side-effects. Additionally in case an error happens when terminating a Snap we catch that error an move on.