[PHP] Allow removing CWD during runtime rotation #2714
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.
Motivation for the change, related issues
Temporarily sets CWD to
/
at the beginning of PHP runtime rotationand restores it at the end of the rotation.
This resolves a Playground CLI issue that left the runtime in an undefined
state when rotating the runtime with a local mount at
/wordpress
Implementation details
There's a chance cleaning up old mounts via mount.unmount()
will attempt removing the CWD. Normally, this would throw
FS.ErrnoError(10) EBUSY and interrupt the PHP runtime rotation,
leaving us in a broken state.
Even though removing the CWD directory is not allowed by the
filesystem, we don't care that much here – we're merely freeing
all the resources allocated by the old filesystem before it's
garbage collected. We are about to recreate the same filesystem
structure and mounts in another PHP runtime.
Therefore, let's suspend the strict EBUSY check by setting the CWD
to / for the cleanup purposes. We'll attempt to restore the original
CWD on the new runtime once we re-apply all the mounts there. We'll
only have a real reason to throw an error if the CWD path does not
exist in the new filesystem after the rotation.
Testing Instructions (or ideally a Blueprint)
CI unit tests.
For manual testing, do this:
Then:
non_existent_function()
. This will nudge the PHP class to rotate the runtime and callunmount()
for all the mounts,Finally, visit the local site. You should see an error screen. Refresh it three times, confirm you still see the same WordPress error screen.