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

Hidden StackOverflow issue (resulting in bug + perf) #125

Closed
stefanpenner opened this issue Apr 20, 2017 · 2 comments
Closed

Hidden StackOverflow issue (resulting in bug + perf) #125

stefanpenner opened this issue Apr 20, 2017 · 2 comments

Comments

@stefanpenner
Copy link
Contributor

resolve.sync of a module with a package.json containing main: '.' will hang for quite some time, (up to 800ms on my machine) and then return return the correct value...

Steps to reproduce:

mkdir -p node_modules/evil/
echo '{"main": "."}' > node_modules/evil/package.json
touch node_modules/evil/index.js
require('resolve').sync('evil') //  => "path/to/node_modules/evil/index.js"  (but very slow)

If the try/catch is removed from https://github.com/substack/node-resolve/blob/master/lib/sync.js#L73 you instead get a fun stack overflow

> require('.').sync('evil')
RangeError: Maximum call stack size exceeded
    at new fs.Stats (fs.js:133:20)
    at Object.fs.statSync (fs.js:907:18)
    at isFile (/Users/spenner/src/substack/node-resolve/lib/sync.js:14:27)
    at loadAsFileSync (/Users/spenner/src/substack/node-resolve/lib/sync.js:45:13)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:68:29)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:70:29)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:70:29)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:70:29)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:70:29)
    at loadAsDirectorySync (/Users/spenner/src/substack/node-resolve/lib/sync.js:70:29)
stefanpenner added a commit to stefanpenner/node-resolve that referenced this issue Apr 20, 2017
stefanpenner added a commit to emberjs/data that referenced this issue Apr 20, 2017
…s about 800ms from ember-cli startup time)

actual upstream issue: browserify/resolve#125
actual upstream PR: browserify/resolve#126

But we should upgrade anyways.
@ljharb
Copy link
Member

ljharb commented Apr 20, 2017

Wow, nice (try/)catch!

@stefanpenner
Copy link
Contributor Author

Wow, nice (try/)catch!

I see what you did...

ljharb added a commit that referenced this issue Jul 26, 2017
 - [New]: add `preserveSymlinks` option (#130)
 - [Fix] `sync`: fix when package.json main = ‘.’ or main = ‘./‘ (#125)
 - [Dev Deps] update `eslint`, `@ljharb/eslint-config`, `tape`
 - [Tests] up to `node` `v8.2`, `v7.10`, `v6.11`; npm 4.6+ breaks on node < 4
 - [Tests] fix 0.6 and linting
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants