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

fix: avoid endless loop when handling symlinks (#109) by @q0rban #109

Merged
merged 7 commits into from
Oct 25, 2024

Conversation

q0rban
Copy link

@q0rban q0rban commented Oct 21, 2024

This resolves #108 for me. I tried to run tests locally to see if this breaks anything, but I guess the tests need to run in CI as they were failing with or without this change on my environment.

Fixes #108

@robertsLando
Copy link
Member

@q0rban I'm not sure that just removing code is the correct way to handle this. You should handle the case of infinite loop like keeping track of paths to be sure you don't hit the same path twice to break the loop

@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

The interesting thing is that the code is already keeping track of the paths. I couldn't figure out a scenario where this code wouldn't result in an infinite loop, which is why I deleted it. But then I realize it is assuming that the paths are not nested at the same level. So I believe the code will work if path/to/some/symlink/index.js is symlinked to path/to/real/index.js (since they have different nesting levels), but I believe it will always loop if path/to/symlink/index.js is linked to path/to/real/index.js since they have the same nesting depth.

Furthermore, I don't believe this function will properly handle the scenario where there are multiple symlinks involved. For example, let's say module chicken is symlinked wholesale into another module:

path/to/node_modules/some-module/node_modules/symchicken -> path/to/node_modules/some-module/node_modules/chicken

but then, what happens if chicken has some links in it as well?

chicken/lib/link.js -> chicken/deeply/nested/index.js

This would result in

path/to/node_modules/some-module/node_modules/symchicken/lib/index.js -> path/to/node_modules/some-module/node_modules/chicken/deeply/nested/index.js

Does that mean this logic needs to recurse? The mind reels.

@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

Incidentally, do you have any tips on running tests locally? I don't see any documentation on that in the repo.

lib/walker.ts Outdated Show resolved Hide resolved
@q0rban
Copy link
Author

q0rban commented Oct 22, 2024

@robertsLando updated the approach and would appreciate your thoughts. The existing logic seems error prone, and thus difficult to ascertain the intent of it.

@robertsLando
Copy link
Member

lib/walker.ts Show resolved Hide resolved
lib/walker.ts Outdated Show resolved Hide resolved
@robertsLando
Copy link
Member

Also please fix lint issues: yarn fix

@robertsLando robertsLando changed the title fix: avoid endless loop when handling symlinks #108 fix: avoid endless loop when handling symlinks Oct 24, 2024
Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

Could you also add a test that covers this?

test-99-#108

lib/walker.ts Show resolved Hide resolved
@q0rban
Copy link
Author

q0rban commented Oct 24, 2024

Could you also add a test that covers this?

test-99-#108

Whoops, apologies, I missed this. Will take a look at what this entails.

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

See review above

@q0rban
Copy link
Author

q0rban commented Oct 24, 2024

Okay, test added. I can confirm that the test just hangs on the main branch, and builds properly on this branch.

@q0rban
Copy link
Author

q0rban commented Oct 24, 2024

See review above

I know, I requested another review after pushing fixes based on that review. :)

Copy link
Member

@robertsLando robertsLando left a comment

Choose a reason for hiding this comment

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

Thanks for this! LGTM :)

@robertsLando robertsLando enabled auto-merge (squash) October 25, 2024 06:20
@robertsLando robertsLando enabled auto-merge (squash) October 25, 2024 06:21
@robertsLando robertsLando changed the title fix: avoid endless loop when handling symlinks fix: avoid endless loop when handling symlinks (#109) by @q0rban Oct 25, 2024
@robertsLando
Copy link
Member

Found improvements on how test works? 😆 Spent 2 days trying to improve them

@robertsLando robertsLando merged commit e41355c into yao-pkg:main Oct 25, 2024
24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Problem with symlinks inside node_modules
2 participants