Skip to content

[release-3.9] Pass throwIfNoEntry to fs.statSync#44582

Merged
DanielRosenwasser merged 1 commit into
release-3.9from
throwIfNoEntry-3.9
Jun 15, 2021
Merged

[release-3.9] Pass throwIfNoEntry to fs.statSync#44582
DanielRosenwasser merged 1 commit into
release-3.9from
throwIfNoEntry-3.9

Conversation

@DanielRosenwasser

@DanielRosenwasser DanielRosenwasser commented Jun 14, 2021

Copy link
Copy Markdown
Member

Ports #41604 to TypeScript 3.9

See nodejs/node#35644 for why we have to do this to avoid potential regressions when users upgrade to Node 16.

Future versions of node will be able to return undefined, rather than
allocating and throwing an exception, when a file is not found.

See nodejs/node#33716
@typescript-bot

Copy link
Copy Markdown
Contributor

This PR doesn't have any linked issues. Please open an issue that references this PR. From there we can discuss and prioritise.

@typescript-bot typescript-bot added the For Uncommitted Bug PR for untriaged, rejected, closed or missing bug label Jun 14, 2021
@fatcerberus

fatcerberus commented Jun 14, 2021

Copy link
Copy Markdown

See nodejs/node#35644 for why we have to do this to avoid potential regressions when users upgrade to Node 16.

I read the associated Node PR for fs.statSync but unless I missed something, it looks like it's an explicit flag that has to be passed in to get the new behavior? Otherwise you get the original (throwing) behavior. So I don't understand why a backport is necessary.

@DanielRosenwasser

Copy link
Copy Markdown
Member Author

@fatcerberus I don't think that's the case. My understanding is that if you don't pass in the flag, exceptions will be thrown with an arbitrarily large call stack capture. @amcasey understands it way better than I do though.

@amcasey

amcasey commented Jun 14, 2021

Copy link
Copy Markdown
Member

@fatcerberus, yes, the new flag is the mitigation. Prior to adding the flag, we were using a different mitigation (suggested by node) - we set the call stack depth to zero for the duration of the stat call. Node PR 35644 circumvents this mitigation by resetting the call stack depth to infinity while construction uvExceptions (like the one for non-existent files). More details: nodejs/node#35644 (comment)

@amcasey

amcasey commented Jun 14, 2021

Copy link
Copy Markdown
Member

The change looks good, but strictly speaking, we need to review all the statSync calls in case 3.9 had some that were dropped by the time I made the change in 4.2 (unlikely).

Edit: confirmed for 3.9, 4.0, and 4.1.

@fatcerberus

fatcerberus commented Jun 14, 2021

Copy link
Copy Markdown

@amcasey Thanks, I was assuming this was a mitigation for a breaking change in Node 16, then I got confused because it didn't seem like throwIfNoEntry was a breaking change (in the Node API). I didn't notice there was a different change causing a perf regression at the time.

@DanielRosenwasser DanielRosenwasser merged commit ebeafcf into release-3.9 Jun 15, 2021
@DanielRosenwasser DanielRosenwasser deleted the throwIfNoEntry-3.9 branch June 15, 2021 20:32
@microsoft microsoft locked as resolved and limited conversation to collaborators Oct 21, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

For Uncommitted Bug PR for untriaged, rejected, closed or missing bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants