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: validate file mode from cpp #52050

Merged
merged 1 commit into from
Mar 14, 2024

Conversation

anonrig
Copy link
Member

@anonrig anonrig commented Mar 12, 2024

This is somewhat similar to #49970, with major modifications to input validation to avoid making this a breaking change due to the input validation on Infinity and NaN on the original PR. Credit to @andremralves for the initial push.

The original PR was blocked due to @tniessen's following comment:

Unless I'm missing something, some functions now don't throw synchronously anymore but instead report the validation error to the callback, which seems unusual for argument validation. I am not sure if that's desirable (or if we treat these things as semver-major).

This does not apply because we throw the error synchronously from the C++ side. A similar work was done on getValidatedFd couple of months ago. (Ref: #51027)

In promisified calls the error was thrown inside an async function, and it is thrown the similar way. For non promisified calls, right now the error is thrown still synchronously but inside the C++ file before any callback execution is done.

The only difference is the order of errors. For example, previously for a callback version of access we were checking the validity of mode and later the validity of callback, right now mode is checked later. According to the documentation, and if I'm not mistaken, this is not a breaking change.

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


And most importantly, I'm back.

@nodejs-github-bot nodejs-github-bot added c++ Issues and PRs that require attention from people who are familiar with C++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run. labels Mar 12, 2024
@anonrig anonrig force-pushed the move-get-valid-mode-to-cpp branch from 9e327e7 to f88f1f1 Compare March 12, 2024 01:19
Copy link
Member

@H4ad H4ad left a comment

Choose a reason for hiding this comment

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

Good to have you back! Just leave some non-blocking comments.

src/util.cc Show resolved Hide resolved
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 12, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 12, 2024
@nodejs-github-bot
Copy link
Collaborator

@anonrig anonrig added the author ready PRs that have at least one approval, no pending requests for changes, and a CI started. label Mar 12, 2024
src/node_file.cc Outdated Show resolved Hide resolved
@RafaelGSS
Copy link
Member

RafaelGSS commented Mar 12, 2024

For example, previously for a callback version of access we were checking the validity of mode and later the validity of callback, right now mode is checked later

Honestly, I have a feeling this should be considered a semver-major. While we do not consider changing the error message to semver-major, changing the order of ERR_CODE should be considered a semver-major.

This, however, should impact only tests (error conditions). So, if everybody agrees, it shouldn't be that bad to land as a non-semver-major PR (mainly on non-LTS lines).


Also, I suspect we are only changing it for performance purposes, right? Would you be able to share benchmarks (preferably in a dedicated machine)?

@anonrig
Copy link
Member Author

anonrig commented Mar 12, 2024

Honestly, I have a feeling this should be considered a semver-major. While we do not consider changing the error message to semver-major, changing the order of ERR_CODE should be considered a semver-major.

@RafaelGSS I'm -0.5 on making this a semver-major change, because of the past pull-requests. For example, similar PR was landed (#51027) without semver-major. Also, it's extremely easy to make this change since by just moving the order of any validate operation, you can easily break the order.

If we follow this path, calling this major change, we should document this before landing this pull-request. But I believe we shouldn't make a claim to preserve the order of errors since it will stall a lot of optimization opportunities by max 1 year (release of major).

Also, I suspect we are only changing it for performance purposes, right? Would you be able to share benchmarks (preferably in a dedicated machine)?

@RafaelGSS The original PR has some benchmark results. I don't have access to a dedicated machine to back this claim, but the results from original PR stands: #49970

@anonrig anonrig force-pushed the move-get-valid-mode-to-cpp branch from f88f1f1 to 211ad4d Compare March 12, 2024 23:34
@anonrig anonrig requested a review from ShogunPanda March 13, 2024 13:33
@anonrig anonrig added the request-ci Add this label to start a Jenkins CI on a PR. label Mar 13, 2024
@github-actions github-actions bot removed the request-ci Add this label to start a Jenkins CI on a PR. label Mar 13, 2024
@nodejs-github-bot
Copy link
Collaborator

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

@anonrig anonrig added the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 13, 2024
@nodejs-github-bot nodejs-github-bot removed the commit-queue Add this label to land a pull request using GitHub Actions. label Mar 14, 2024
@nodejs-github-bot nodejs-github-bot merged commit 3ec20f2 into nodejs:main Mar 14, 2024
55 checks passed
@nodejs-github-bot
Copy link
Collaborator

Landed in 3ec20f2

rdw-msft pushed a commit to rdw-msft/node that referenced this pull request Mar 26, 2024
PR-URL: nodejs#52050
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request May 2, 2024
PR-URL: #52050
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
marco-ippolito pushed a commit that referenced this pull request May 3, 2024
PR-URL: #52050
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
jcbhmr pushed a commit to jcbhmr/node that referenced this pull request May 15, 2024
PR-URL: nodejs#52050
Reviewed-By: Vinícius Lourenço Claro Cardoso <contact@viniciusl.com.br>
Reviewed-By: Daniel Lemire <daniel@lemire.me>
Reviewed-By: Paolo Insogna <paolo@cowtech.it>
Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
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++. lib / src Issues and PRs related to general changes in the lib or src directory. needs-ci PRs that need a full CI run.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants