Prevent dtor of generator in suspended fiber #10462
Merged
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.
Fixes #9916
The shutdown sequence calls the destructor of any live generator or fiber (or any object).
When a fiber is suspended in a generator, the fiber destructor will resume the execution the generator, which may be already be destroyed. This leads to the issues described in #9916.
Because of this, we must not attempt to destroy a generator that was executing in a suspended fiber.
The fiber destructor conveniently throws a zend_ce_graceful_exit in the fiber context, which will also properly terminate the generator (and execute its finally blocks). I believe that this has the same semantics as the generator destructor.