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

fs: add v8 fast api to closeSync #53627

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Jun 28, 2024

Adds V8 Fast API to fs.closeSync(fd) implementation

cc @nodejs/performance @nodejs/fs @nodejs/cpp-reviewers

@anonrig anonrig requested a review from tniessen June 28, 2024 14:58
@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run. labels Jun 28, 2024
src/node_file.cc Outdated Show resolved Hide resolved
src/node_file.cc Outdated Show resolved Hide resolved
src/node_file.cc Show resolved Hide resolved
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

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

lgtm

src/node_file.cc Outdated Show resolved Hide resolved
@anonrig anonrig added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. request-ci Add this label to start a Jenkins CI on a PR. labels Jul 1, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Jul 3, 2024
src/node_file.cc Outdated
options.fallback = true;
} else {
// Only remove unmanaged fds if the close was successful.
env->RemoveUnmanagedFd(fd);
Copy link
Member

@joyeecheung joyeecheung Jul 11, 2024

Choose a reason for hiding this comment

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

This is unsafe, RemoveUnmanagedFd() can call ProcessEmitWarning() which calls back into JS process.emitWarning() and violates the fast API protocol. Although since it's just a warning, you could probably just add a parameter to RemoveUnmanagedFd to make it invoke ProcessEmitWarning() later in a native Immediate, and scheduling a native immediate is safe.

Copy link
Member Author

Choose a reason for hiding this comment

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

If I understood you correctly, inside RemoveUnmanagedFd you want me to conditionally call the following right?

SetImmediateThreadsafe([](Environment* env) {
  ProcessEmitWarning(
        this, "File descriptor %d closed but not opened in unmanaged mode", fd);
});

If not, what is the correct way to schedule a native immediate?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I got it. Can you review it again? @joyeecheung

@anonrig
Copy link
Member Author

anonrig commented Jul 12, 2024

cc @nodejs/cpp-reviewers

@anonrig anonrig requested a review from mcollina July 14, 2024 23:26
@anonrig anonrig requested review from Qard, jasnell and H4ad July 14, 2024 23:26
@@ -1841,12 +1841,23 @@ void Environment::AddUnmanagedFd(int fd) {
}
}

void Environment::RemoveUnmanagedFd(int fd) {
void Environment::RemoveUnmanagedFd(int fd, bool schedule_native_immediate) {
Copy link
Member

Choose a reason for hiding this comment

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

Not: generally not a fan of bool arguments like this. I prefer enums that allow the call sites to be clearer about what the argument is as opposed to just true or false.

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 15, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Jul 15, 2024
@nodejs-github-bot nodejs-github-bot merged commit ed6f45b into nodejs:main Jul 15, 2024
52 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in ed6f45b

aduh95 pushed a commit that referenced this pull request Jul 16, 2024
PR-URL: #53627
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
aduh95 pushed a commit that referenced this pull request Jul 16, 2024
PR-URL: #53627
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
@aduh95 aduh95 mentioned this pull request Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
author ready PRs that have at least one approval, no pending requests for changes, and a CI started. c++ Issues and PRs that require attention from people who are familiar with C++. fs Issues and PRs related to the fs subsystem / file system. needs-ci PRs that need a full CI run.
8 participants