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

[BUG] put.stream can crash the process with unhandled exception, even when error handler is attached #249

Closed
1 task done
kalinkrustev opened this issue Nov 22, 2023 · 0 comments · Fixed by #250
Closed
1 task done
Labels
Bug Needs Triage needs an initial review

Comments

@kalinkrustev
Copy link
Contributor

Is there an existing issue for this?

  • I have searched the existing issues

Current Behavior

Process terminates with error:

node:internal/process/promises:289
            triggerUncaughtException(err, true /* fromPromise */);
            ^

[Error: EACCES: permission denied, open 'tmp/3164ed41'] {
  errno: -13,
  code: 'EACCES',
  syscall: 'open',
  path: 'tmp/3164ed41'
}

Expected Behavior

Process does not terminate and the stream error handler is called

Steps To Reproduce

Run the following script. It will change the tmp folder permission, so that an error is triggered. It can happen in other circumstances too (of of disk space, etc.)
In certain cases this results in a lingering rejected promise handleContentP within lib/content/write.js
In the example, such case is when the readable stream has not ended.

const {Readable} = require('stream');
const {chmod} = require('fs/promises');
const {existsSync} = require('fs');
const cacache = require('cacache');

const read = (...params) => new Readable({
    read(size) {
        if (params.length) this.push(params.shift());
    }
});

require('http').createServer().listen(() => console.log('listening'));

((async()=>{
    if (existsSync('./tmp')) await chmod('./tmp', 0777);
    await cacache .put('.', 'key1', '1')
    await chmod('./tmp', 0555);
    return read('2').pipe(cacache.put.stream('.', 'key2')).on('error', console.error);

})()).catch(console.error);

Environment

  • Node: v20.9.0
  • OS: Linux
@kalinkrustev kalinkrustev added Bug Needs Triage needs an initial review labels Nov 22, 2023
kalinkrustev added a commit to kalinkrustev/cacache that referenced this issue Nov 22, 2023
This attaches a catch handler to the handleContentP promise, as in some cases the flush is not called before node decides that this is an unhandled promise rejection.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Needs Triage needs an initial review
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant