-
-
Notifications
You must be signed in to change notification settings - Fork 133
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
prevent app crash on error event #80
Conversation
It looks like some defaults changed in |
I've updated dependencies and fixed lint issues, so if you rebase from master the diff will be a lot cleaner :) |
# Conflicts: # changelog.md
The purpose of the `build:prettier` script is cleanup the un-pretty Bablel output in `lib`, so changing the glob to `src` doesn’t make sense. The `lint:prettier` glob includes `**/` so that it searches nested directories.
Thanks for getting your hands dirty! I hesitate to commit to any approach with handling these error when we don't have tests yet. It is really hard to be sure what's going on otherwise; if it fixes issues or creates new ones. Here is the issue for adding such tests: #79. Does the ordering of the file Will this silence any errors that really should cause a crash? Does this fix #77? Which is a better approach, a noop error listener on the file ( |
- Improved comment. - More efficient noop function.
Hey @jaydenseric – I rebased from master; thanks for that. I also had made some changes to the lint scripts so that it would pass locally. Let me know if you'd rather I just include the one change and a failing lint check. As far as your concern RE tests go, I really appreciate that and will look for a way to add that here. The challenge with making a "real world" test is that we're essentially testing a race condition, and a correct, deterministic test won't look realistic. Adding an error handler on the parser ( This is a really sane default for node, but currently there's no way for a user to synchronously add event handlers to the streams created by I'm not sure about #78, but your suggestion of adding a handler for There's another bigger change I'm working on that may be related to #78, but I'll put up a PR and we can discuss that there. |
This actually appears necessary for tests to pass on node v10 |
@mike-marcacci you force pushed updates that wiped all of my commits on your branch… |
I just force-pushed it back to the original state, the only loss from you side is adding the no-op error handler to the parser. Be sure to pull first thing, and try not to regularly use force-push 😅 It's likely we will need one of the handlers, but maybe not both? My preference would be one on the parser itself as it might catch more (errors to do with the parser somehow but not individual files). |
My apologies about the force-push; I totally blanked that you had made those changes, and do have a habit of force-pushing to PR branches with squashed or rebased changes. Anyhow, I don't believe that errors propagate through piped streams the way you're suggesting. I had to write a small little test to make sure though: const fs = require('fs');
const { Transform } = require('stream');
const stream1 = fs.createReadStream('input.txt');
stream1.on('error', () => {
console.error('Error emitted on stream1');
});
const stream2 = new Transform({
transform(chunk, encoding, callback) {
stream2.emit('error', new Error())
setTimeout(() => {
callback(null, chunk.toString('utf8'));
}, 1000);
}
});
stream2.on('error', () => {
console.error('Error emitted on stream2');
});
const stream3 = fs.createWriteStream('output.txt');
stream3.on('error', () => {
console.error('Error emitted on stream3');
});
stream1.pipe(stream2).pipe(stream3) This results in:
Note that you won't see an const fs = require('fs');
const { Transform } = require('stream');
const stream1 = fs.createReadStream('input.txt');
const stream2 = new Transform({
transform(chunk, encoding, callback) {
stream2.emit('error', new Error())
setTimeout(() => {
callback(null, chunk.toString('utf8'));
}, 1000);
}
});
const stream3 = fs.createWriteStream('output.txt');
stream1.pipe(stream2).pipe(stream3) The app crashes:
This is true even if handlers are present on Therefore, adding a handler to the parser won't help with errors emitted on individual file streams and vice versa. |
BTW (regarding #80 (comment)) I fixed the issue with the tests in Node.js v10 with 528216f, although the error handlers will still likely be necessary for other reasons. It's a little concerning that adding these no-op error handlers would have swept a valid bug under the carpet. |
OK, I've done a small refactor and added tests for client-aborted requests. The middleware now only adds a handler to unhandled streams just before it triggers an The new test ensures that:
Either an error in the parser or a closed connection will result in this behavior. |
Closing this in favor of #81. |
It's possible for an
Upload
's stream to be ready before userland code has had a chance to attach event handlers or pipe it somewhere. If the client disconnects during this time, anerror
event is emitted:Because no
error
event listener has been assigned, the entire app will crash. While this is a great default for streams in general, it's probably not the desired behavior here. I've added a noop handler for the error event to prevent crashes.