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

createWriteStream on Ubuntu not using default autoClose option #17951

Closed
rush1818 opened this issue Jan 2, 2018 · 8 comments
Closed

createWriteStream on Ubuntu not using default autoClose option #17951

rush1818 opened this issue Jan 2, 2018 · 8 comments
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@rush1818
Copy link

rush1818 commented Jan 2, 2018

  • Version: v9.2.1 and v9.3.0
  • Platform: Ubuntu 16.04

I am using createWriteStream in my code which throws the following error on Ubuntu:

events.js:180
    throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function

Adding the autoClose option solves this error. The docs mention that autoClose=true by default so not sure why I had to explicitly specify it again.

The code does not throw error when running on mac 10.12.6 with node 9.2.1 and 9.3.0.

The code works without any errors on Ubuntu 16.04 when using node 8.9.3. Looks like something changed after 8.9.3 for the Ubuntu build which is causing this issue.

@bnoordhuis bnoordhuis added the fs Issues and PRs related to the fs subsystem / file system. label Jan 3, 2018
@bnoordhuis
Copy link
Member

How do you call it? Please post a standalone code example.

@rush1818
Copy link
Author

rush1818 commented Jan 3, 2018

Here you go:

const FS = require('fs');
const zlib = require('zlib');

const gzip = zlib.createGzip();
const inputStream = FS.createReadStream('./file.txt');
const outputStream = FS.createWriteStream('./output.gz');

outputStream.on('finish', function () {
  outputStream.close();
 // Perform other logic as well
});

inputStream.pipe(gzip).pipe(outputStream);

This code block did not work on my Mac as well. I am calling the close() method to close the writeStream. When I changed it to use destroy() instead it worked.

On Ubuntu, one of my team mate was able to solve the error by changing adding the {autoClose: true} option and leaving the close() as is.

Also, the project has been in service for 1+ years without errors so it could be that there are some API changes I missed when I upgraded node to v9.

@bnoordhuis
Copy link
Member

bnoordhuis commented Jan 4, 2018

Thanks. Just so we're on the same page, can you post the full stack trace that you got?

edit: that said, I suspect e5c290b is responsible for what you're seeing.

@timotew
Copy link
Contributor

timotew commented Jan 4, 2018

@bnoordhuis I try to reproduce the error, This is what i got on Ubuntu:

events.js:180
    throw new errors.TypeError('ERR_INVALID_ARG_TYPE', 'listener', 'Function');
    ^

TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type Function
    at _addListener (events.js:180:11)
    at WriteStream.addListener (events.js:240:10)
    at WriteStream.close (fs.js:2302:10)
    at WriteStream.<anonymous> (/home/timothy/nood/app.js:9:16)
    at WriteStream.emit (events.js:164:20)
    at finishMaybe (_stream_writable.js:605:14)
    at afterWrite (_stream_writable.js:456:3)
    at onwrite (_stream_writable.js:446:7)
    at fs.js:2246:5
    at FSReqWrap.wrapper [as oncomplete] (fs.js:703:5)

@bnoordhuis
Copy link
Member

@timotew Thanks!

@mcollina Looks like e5c290b#diff-9a205ef7ee967ee32efee02e58b3482dR2275 needs an additional type check.

@bnoordhuis bnoordhuis added the v9.x label Jan 4, 2018
@mcollina
Copy link
Member

mcollina commented Jan 4, 2018

@bnoordhuis yes indeed! I'll work on a fix tomorrow.

@rush1818
Copy link
Author

rush1818 commented Jan 4, 2018

I get the same error as @timotew . Thanks for identifying the cause!

mcollina added a commit to mcollina/node that referenced this issue Jan 5, 2018
Refactor WriteStream.prototype.close and WriteStream.prototype._destroy
to always call the callback passed to close in order. Protects from
calling .close() without a callback.

Fixes: nodejs#17951
See: nodejs#15407
MylesBorins pushed a commit that referenced this issue Jan 9, 2018
Refactor WriteStream.prototype.close and WriteStream.prototype._destroy
to always call the callback passed to close in order. Protects from
calling .close() without a callback.

Fixes: #17951
See: #15407

PR-URL: #18002
Fixes: #17951
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
MylesBorins pushed a commit that referenced this issue Jan 10, 2018
Refactor WriteStream.prototype.close and WriteStream.prototype._destroy
to always call the callback passed to close in order. Protects from
calling .close() without a callback.

Fixes: #17951
See: #15407

PR-URL: #18002
Fixes: #17951
Reviewed-By: Ben Noordhuis <[email protected]>
Reviewed-By: James M Snell <[email protected]>
@mcollina
Copy link
Member

mcollina commented Jan 10, 2018

The fix will be released in 9.4.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants