Prevent dtor of generator in suspended fiber - #10462
Merged
Merged
Conversation
Generators that suspended a fiber should not be dtor because they will be executed during the fiber dtor. Fiber dtor throws an exception in the fiber's context in order to unwind and execute finally blocks, which will also properly dtor the generator.
bwoebi
previously approved these changes
Jan 27, 2023
trowski
approved these changes
Jan 27, 2023
trowski
left a comment
Member
There was a problem hiding this comment.
I too am pleasantly surprised at the simplicity of this patch. I'll be very happy to get this in as I've been getting reports of CI failures using AMPHP v3 due to this issue.
arnaud-lb
marked this pull request as ready for review
January 27, 2023 18:31
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.