-
-
Notifications
You must be signed in to change notification settings - Fork 242
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
callback parameter is missing from 'write' and 'end' methods #46
Comments
Hi! What version of Node.js are you using? It doesn't seem to exist in 0.10, at least. |
Hi! I'm using 0.12 (https://nodejs.org/api/stream.html#stream_writable_write_chunk_encoding_callback) But I guess this parameter was there all along. That's the node way :-) (https://nodejs.org/docs/v0.10.0/api/stream.html#stream_writable_write_chunk_encoding_callback_1) |
This module is only for HTTP streams, which in Node.js are not actually the normal streams at all. For example, this is the actual source for the |
It looks like the |
Looks like the callback argument to |
I'm using Node 0.10.40. I supply the callback on second argument in res.write() and It's work but when compression middleware it throws an error:
which is my callback function. I try to fix it by change second arguments to "utf-8" and move callback to third argument. The error was gone but callback never get call. update: I use node 4.1.2. Callback not get call too. |
I just ran into this problem as well and it took me a long time to figure out what was going on as it unexpectedly breaks var express = require('express');
var compression = require('compression')
var app = express();
app.use(compression())
app.get('/', function (req, res) {
res.write('Hello World!', 'utf-8', function() {
console.log('will never be called since compression overrode res.write without the callback parameter');
});
res.end();
});
app.listen(3000); This is worse if you put the Is there any update as to when this will be fixed? It seems simple enough of a fix if you just used |
There is the PR #80 that is actively being worked on that would resolve this. |
There seems to be a lot going on in that PR discussion wise. From what I can gather you seem to want two different PRs made: one that fixes this bug specifically and the other that fixes the |
Hi @straker, yes there is a lot of discussion. The reference PR is specific to add the callbacks; the second PR to fix the flush bug was never made.
So there is more to fixing it than that, and there has been a lot of discussion around that very point in the PR :) The main point is that you cannot just pass the callbacks through, because otherwise, it will make the callbacks even more unpredictable on Node.js 0.8 and 0.10, which changes this module from "if you use this, you cannot use callbacks" to "if you use this, you can use callbacks, except on Node.js 0.8 and 0.10, where normally you cannot use callbacks, but now you can, but not if the client sends headers to not compress the output". |
Ah, I thought that PR was to fix the flush bug. I'm not sure if I understand what you mean. How does passing through the arguments from compressions I thought that's what the two different PRs were suppose to separate because the PR you referenced looks(ed) at the argument list to compression's |
No, it doesn't, which was the point I was bringing up, that the PR is just trying to add callback support instead of actually fixing the flush bug.
Because the zlib stream in 0.8 and 0.10 does support the callbacks. You're welcome to also make a pull request if you have a different approach, but every time you keep talking about calling |
I see, I misunderstood how that all worked together. I can see how that complicates maters significantly. I'll investigate further to see if I can come up with something else that will work taking into account zlib. Thanks for the responses. |
No problem, @straker! I would love to get this fixed, where it doesn't introduce even more head-aches for debugging :S I just have had so many more higher-priority issues to work around, and besides from this initial issue, I never even heard from anyone besides two just suddenly that it was even a big issue (probably because, when surveying The Express.js TC has spoken about Node.js support recently, and we are wiling to start bumping majors to drop Node.js 0.8 support, but with Node.js 0.10 still supported by the Node.js foundation (which we are a part of) and still demand for Node.js 0.10 support among corporate, dropping 0.10 is still a bit iffy. I bring that up because dropping those versions would make this a non-issue... |
The methods 'write' and 'end' don't accept a 'callback' parameter - the underlaying http response stream does. Therefore there is a different runtime behaviour when sending off the data in chunks (waiting for the response to be written) when using compression (callback will not be called and the program hangs)
The text was updated successfully, but these errors were encountered: