Skip to content

Conversation

adamziel
Copy link
Collaborator

@adamziel adamziel commented Oct 1, 2025

Motivation for the change, related issues

Temporarily sets CWD to / at the beginning of PHP runtime rotation
and 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:

cli.ts server --mount-before-install=./test-site/:/wordpress

Then:

  1. Let it do the setup.
  2. Modify wp-content/themes/twentytwentyfour/functions.php to call non_existent_function(). This will nudge the PHP class to rotate the runtime and call unmount() for all the mounts,
  3. Run the following command:
cli.ts server --mount-before-install=./test-site/:/wordpress  --skip-wordpress-setup

Finally, visit the local site. You should see an error screen. Refresh it three times, confirm you still see the same WordPress error screen.

*/
export function rotatePHPRuntime({
php,
cwd,
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was unused anyway.

@adamziel adamziel merged commit da23203 into trunk Oct 1, 2025
27 checks passed
@adamziel adamziel deleted the nodefs-mount-restore-cwd-after-rotation branch October 1, 2025 14:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant