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

"write after end" error with immutable option #23

Closed
JcBernack opened this issue Mar 29, 2018 · 4 comments
Closed

"write after end" error with immutable option #23

JcBernack opened this issue Mar 29, 2018 · 4 comments
Assignees

Comments

@JcBernack
Copy link
Contributor

I can't get the rotating file stream to work with the immutable option set:

const rfs = require('rotating-file-stream');

const stream = rfs('yolo.log', {
    interval: '1m',
    immutable: true,
});

stream.write('abc\n');

stream.end();

The write immediately throws an exception:

events.js:141
      throw er; // Unhandled 'error' event
      ^

Error: write after end
    at writeAfterEnd (_stream_writable.js:167:12)
    at RotatingFileStream.Writable.write (_stream_writable.js:212:5)
    at Object.<anonymous> (/projectdir/yolo.js:8:8)
    at Module._compile (module.js:409:26)
    at Object.Module._extensions..js (module.js:416:10)
    at Module.load (module.js:343:32)
    at Function.Module._load (module.js:300:12)
    at Function.Module.runMain (module.js:441:10)
    at startup (node.js:140:18)
    at node.js:1043:3

Do you have any idea what is happening here?
Thanks

@iccicci
Copy link
Owner

iccicci commented Mar 29, 2018

Hi @JcBernack ,

first of all I suggest to ad an error event listener before your first write:

stream.on('error', console.log.bind(console));

this should help you revealing the actual error.

Please let me know if this helps you solving your problem,
iCC

@iccicci iccicci self-assigned this Mar 29, 2018
@JcBernack
Copy link
Contributor Author

Hi, thanks for the response.

I already did that, it just logs the same error message: [Error: write after end]

@JcBernack
Copy link
Contributor Author

Found something:
The error we are not seeing is immediately thrown on creation, before we can even register the error event handler.

It origins in this line:
https://github.com/iccicci/rotating-file-stream/blob/master/index.js#L204

It is caused by the generator function because it expects time to be a Date object, but in this case it is a unix-timestamp from your now() function.

I replaced the this.now() with a new Date() in this line and it seems to work:
https://github.com/iccicci/rotating-file-stream/blob/master/index.js#L197

@JcBernack
Copy link
Contributor Author

Submitted a PR with the little change, see #24

iccicci added a commit that referenced this issue Mar 30, 2018
iccicci added a commit that referenced this issue Apr 5, 2018
@iccicci iccicci closed this as completed Apr 5, 2018
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

No branches or pull requests

2 participants