Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Snapshotting is persisting the cwd #49675

Closed
arcanis opened this issue Sep 16, 2023 · 1 comment · Fixed by #49684
Closed

Snapshotting is persisting the cwd #49675

arcanis opened this issue Sep 16, 2023 · 1 comment · Fixed by #49684
Labels
confirmed-bug Issues with confirmed bugs. snapshot Issues and PRs related to the startup snapshot

Comments

@arcanis
Copy link
Contributor

arcanis commented Sep 16, 2023

Version

v20.6.1

Platform

Darwin

Subsystem

snapshots

What steps will reproduce the bug?

Generate a snapshot of the given script, then run it from a different directory. The process.cwd() function will keep returning the cwd you had while building the snapshot.

const v8 = require(`v8`);

if (v8.startupSnapshot.isBuildingSnapshot()) {
    v8.startupSnapshot.setDeserializeMainFunction(() => {
        console.log(process.cwd());
    });
}

How often does it reproduce? Is there a required condition?

No response

What is the expected behavior? Why is that the expected behavior?

It should return the actual cwd.

What do you see instead?

It returns the cwd at the time of --build-snapshot.

Additional information

No response

@bnoordhuis bnoordhuis added confirmed-bug Issues with confirmed bugs. snapshot Issues and PRs related to the startup snapshot labels Sep 17, 2023
@bnoordhuis
Copy link
Member

It's because the current working directory is cached (introduced in #27224 FWIW, before snapshots were a thing.)

Should be easy to fix by clearing cachedCwd in lib/internal/bootstrap/switches/does_own_process_state.js. PR welcome.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. snapshot Issues and PRs related to the startup snapshot
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants