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
Set encoding of the request to utf8 before listening on data events #305
Set encoding of the request to utf8 before listening on data events #305
Conversation
Hmm, it looks this PR doesn't change the behavior to me. Anyway, I'd like to reproduce the problem. How can I do that? |
We are seeing this in #356 and primus/primus#196 (comment). It is very hard to reproduce and I have not successfully been able to do so, but I am seeing it hit our production servers about once or twice a week. Last time I saw it, I was running iojs v2.5.0. I am, however, able to reproduce the issue using the following script: var stream = require('stream');
var a = new stream.PassThrough();
a.write('foobar');
console.log('before handler');
a.on('data', function(chunk) {
console.log('data handler', chunk);
});
console.log('after handler');
a.setEncoding('utf8'); The correct output is:
Every Node version > 0.10 has the correct behavior that I tested, but 0.10.40 does not:
Since engine.io still supports |
For future reference, this appears to be the commit that fixed the bug, which landed in v0.11.5. It's also known as streams3. It makes the commit comment |
@STRML good job! |
@nkzawa Could you please review? |
@STRML 👍 |
…g-on-data Set encoding of the request to utf8 before listening on data events
Awesome! Thank you :) |
Thanks @rauchg, had this biting us at random for a long time now. |
Yep, I'll get this published asap |
Switch from depending on a tarball URL to the published component-emitter package at its latest version. Change all references to emitter module to the new component-emitter name.
Upgrade component-emitter to 1.1.2, fix #305
Hello,
I'm running into a case where the data event handler is called before the set encoding is called, in this case I end up having
chunks
as an empty string anddata
is a Buffer thus raising the error `Possibly unhandled TypeError: Object has no method 'copy'I always thought the data event handler was called after the next tick, but it does not seem to be the case, or I am missing something.
Moving the setEncoding method before attaching the handler resolves my issue.
Thank