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

Close the file descriptor if exiting upload via an error. #80

Merged
merged 1 commit into from
Nov 26, 2018

Conversation

macdja38
Copy link
Contributor

@macdja38 macdja38 commented Oct 15, 2018

This fixes https://npm.community/t/unhelpful-error-message-when-publishing-without-logging-in-error-eperm-operation-not-permitted-unlink/1377/3 and the other dozen or so issues that that link references, and possibly many more involving poor error messages from errors thrown by the upload function.

@zkat you mentioned you could take a look at any fixes / answer any questions, if you could look this over and let me know if this is a good / valid approach that would be fantastic, thanks! (it wasn't a race condition, luckily :P).

it may also be helpful to add something like

    if (!auth.token && !(auth.username && auth.password)) {
      log.warn('publish', 'not logged in')
    }

just before we even open the first file descriptor to make sure that even if the error message is completely wrong something in the log will give users a clue what may be going on. I took the method of looking for login creds from the logout method, I'm not sure that's valid or if alternatives to npm exist that don't require credentials but users could still publish to.

Triage of the issue:

  1. The upload function throws an error
  2. As that error bubbles through cacache it tries to delete the tmpdir as it should
  3. It can't delete the temp dir as the upload function's readFileStream to the tar it was trying to upload is still open.
  4. cacache throws an error about it's inability to remove the dir, which suppresses the upload function's error.

This fixes https://npm.community/t/unhelpful-error-message-when-publishing-without-logging-in-error-eperm-operation-not-permitted-unlink/1377/3 and the other dozen or so issues that that link references, and possibly many more involving poor error messages from errors thrown by the upload function. 

@zkat you mentioned you could take a look at any fixes / answer any questions, if you could look this over and let me know if this is a good / valid approach that would be fantastic, thanks! (it wasn't a race condition, luckily :P).

it may also be helpful to add something like 
```
    if (!auth.token || !(auth.username && auth.password)) {
      log.warn('publish', 'not logged in')
    }
```
just before we even open the first file descriptor to make sure that even if the error message is completely wrong something in the log will give users a clue what may be going on. I took the method of looking for login creds from the logout method, I'm not sure that's valid or if alternatives to npm exist that don't require credentials but users could still publish to.

Triage of the issue:

1. The upload function throws an error
2. As that error bubbles through [cacache](https://www.npmjs.com/package/cacache#with-tmp) it tries to delete the tmpdir as it should
3. It can't delete the temp dir as the upload function's readFileStream to the tar it was trying to upload is still open.
4. [cacache](https://www.npmjs.com/package/cacache#with-tmp) throws an error about it's inability to remove the dir, which suppresses the upload function's error.
@macdja38 macdja38 requested a review from a team as a code owner October 15, 2018 04:14
@zkat zkat added the semver:patch semver patch level for changes label Nov 13, 2018
Copy link
Contributor

@zkat zkat left a comment

Choose a reason for hiding this comment

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

This LGTM!

@zkat zkat changed the base branch from latest to release-next November 13, 2018 15:11
@zkat zkat merged commit 71d8fb4 into npm:release-next Nov 26, 2018
zkat pushed a commit that referenced this pull request Dec 10, 2018
This fixes https://npm.community/t/unhelpful-error-message-when-publishing-without-logging-in-error-eperm-operation-not-permitted-unlink/1377/3 and the other dozen or so issues that that link references, and possibly many more involving poor error messages from errors thrown by the upload function. 

@zkat you mentioned you could take a look at any fixes / answer any questions, if you could look this over and let me know if this is a good / valid approach that would be fantastic, thanks! (it wasn't a race condition, luckily :P).

it may also be helpful to add something like 
```
    if (!auth.token || !(auth.username && auth.password)) {
      log.warn('publish', 'not logged in')
    }
```
just before we even open the first file descriptor to make sure that even if the error message is completely wrong something in the log will give users a clue what may be going on. I took the method of looking for login creds from the logout method, I'm not sure that's valid or if alternatives to npm exist that don't require credentials but users could still publish to.

Triage of the issue:

1. The upload function throws an error
2. As that error bubbles through [cacache](https://www.npmjs.com/package/cacache#with-tmp) it tries to delete the tmpdir as it should
3. It can't delete the temp dir as the upload function's readFileStream to the tar it was trying to upload is still open.
4. [cacache](https://www.npmjs.com/package/cacache#with-tmp) throws an error about it's inability to remove the dir, which suppresses the upload function's error.

Fixes: https://npm.community/t/unhelpful-error-message-when-publishing-without-logging-in-error-eperm-operation-not-permitted-unlink/1377/3
PR-URL: #80
Credit: @macdja38
Reviewed-By: @zkat
antongolub pushed a commit to antongolub-forks/npm-cli that referenced this pull request May 18, 2024
`linkGently` would return true if a link target had been visited before.
`linkBin` would then chmod the link `to`, regardless of whether this
file exists. This causes `npm install` to fail if multiple packages link
to a non-existent bin with the same name.

By returning false in `linkGently`, `linkBin` no skips the chmod on the
non-existent file.


## References

Fixes npm#4597
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver:patch semver patch level for changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants