Thank you for the report and test case!
I have submitted a PR to fix the issue and should be in the next
release: https://github.com/luvit/luvit/pull/803
Regards, Ryan
On Sun, Aug 23, 2015, at 07:14 AM, alfred wrote:
> If it helps any ive traced the events as generated by both node
> and luvit:
>
> //Node code //luvit code response: pipe response: pipe readable:
> resume readable: resume readable: open readable: open readable: data
> readable: data readable: pause readable: pause response: drain
> response: drain(r) ... ... readable: data readable: data readable:
> pause readable: pause response: drain response: drain(r) readable:
> readable readable: readable readable: end readable: end response:
> prefinishresponse: prefinish response: finish response: finish
> response: unpipe response: unpipe readable: close response: end
> response: end(r) <-- disregard as it belongs to the previous
> emit('end'...) call response: end(r) <-- Happens when i Ctrl-C the
> wget process - this is generated by the underlying socket response:
> close(r) <-- " " " " " "
>
> using the following code: Lua: local http = require('http') local fs =
> require('fs') local path = require('path')
>
> local function interceptEmit(stream, logString) local oldEmit =
> stream.emit stream.emit = function(self, type, ...)
> print(logString .. type) return oldEmit(self, type, ...) end end
>
> local server = http.createServer(function (req, res) local f =
> fs.createReadStream('somefile.txt') interceptEmit(f, 'readable: ')
> interceptEmit(res, 'response: ') --The following have been pre-bound
> in ServerResponse res:on('close', function() print('response:
> close(r)')end) res:on('drain', function() print('response:
> drain(r)')end) res:on('end', function() print('response:
> end(r)')end) f:pipe(res) end):listen(1337, function() print('Server
> running 1337') end)
>
> Javascript (node) var fs = require('fs'); // file system var http =
> require('http');
>
> function interceptEmit(stream, stamp){ var emit = stream.emit;
> stream.emit = function(){ console.log(stamp, arguments[0]);
> return emit.apply(stream, arguments); } }
>
> var server = http.createServer(function (req, res) { var rstream =
> fs.createReadStream('somefile.txt'); interceptEmit(rstream,
> 'readable: '); interceptEmit(res, 'response: '); rstream.pipe(res);
> }); server.listen(8000, function(){ console.log('listening on port
> 8000'); });
>
>
>
>
> On Saturday, 22 August 2015 22:48:27 UTC+8, alfred wrote:
>> The following code does not close the response, as it should for a
>> chunked response.
>>
>> local http = require('http') local fs = require('fs')
>>
>> local server = http.createServer(function (req, res) local f =
>> fs.createReadStream('somefile.txt') -- f:on('end',
>> function()res:finish()end) res:setHeader("Content-Type", "application/octet-
>> stream") f:pipe(res) end):listen(1337, function() print('Server
>> running on 1337') end)
>>
>> The equivalent code works in nodejs.
>>
>> To test I used: wget -o /dev/null http://localhost:1337
>>
>> The response object is emitting events "finish", "unpipe" and "end"
>> after the readstream's "end" event. But the http "transaction" is not
>> terminated.
>>
>> I'd give this a go but I thought I'd better ask if this is a known
>> problem? if not, do you have a suggestion as to where it might be?
>>
>>
>> Workaround is uncomment the line with "f:on('end'..."
>>
>
> --
>
You received this message because you are subscribed to the Google
Groups "luvit" group.
>
To unsubscribe from this group and stop receiving emails from it, send
an email to [email protected].
>
For more options, visit https://groups.google.com/d/optout.
--
You received this message because you are subscribed to the Google Groups
"luvit" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.