feat: support waiting for background tasks on the per_worker
policy
#451
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.
What kind of change does this PR introduce?
Feature
Description
This PR prevents the supervisor from switching the user worker to the early drop state if there is a microtask (Promise) queued in the user worker.
Note that this does not track all promises, only those marked for tracking at runtime by extra typing, also, this support only works in the
per_worker
policy.Type declaration
Usage
Side note
This behavior will interact with the graceful shutdown.
In other words, even if runtime is during the graceful shutdown state, if there are background tasks left in the user worker, the supervisor will wait for them to be completed unless it is forced to terminate by the resource limit.
The timeout for the graceful shutdown specified by the flag in cli is respected, so the maximum time that the supervisor can wait for background tasks is limited to the graceful shutdown timeout. (For each user worker)
Future note
Today, I have made it so that this can only be done by extra typing, which is due to the limitation that we cannot get consistent promise counts that can determine whether all background tasks created by core scripts or our deno ext implementation have been resolved.
Most of these inconsistencies seem to occur in our HTTP request listener implementation (not sure), and if this is resolved, extra typing may not be necessary, so it should be reviewed later.