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

"premature close" error not thrown in node 8.2.0 or newer #14

Closed
trygve-lie opened this issue Aug 30, 2017 · 2 comments
Closed

"premature close" error not thrown in node 8.2.0 or newer #14

trygve-lie opened this issue Aug 30, 2017 · 2 comments

Comments

@trygve-lie
Copy link

trygve-lie commented Aug 30, 2017

There has been a subtile change in node 8.2.0 and newer (nodejs/node#14024) which affect this module.

In a situation where a outgoing http stream is terminated prematurly, this module will pass on an error object on close in node versions 8.1.4 and older. In node version 8.2.0 this module will not pass on an error object.

Here is an example:

const { get, createServer } = require('http');
const eos = require('end-of-stream');

let external;

// Http server
createServer((req, res) => {
    res.writeHead(200);
    setTimeout(() => {
        external.abort();
        res.end('Hello World\n');
    }, 1000);
}).listen(3000);

// Proxy server
createServer((req, res) => {
    get('http://127.0.0.1:3000', inner => {
        eos(res, (err) => {
            console.log('stream ended', err);
        });
        inner.pipe(res);
    });
}).listen(3001, () => {
    external = get('http://127.0.0.1:3001');
});

In node version 8.1.4 or older this will output:

stream ended Error: premature close
    at ServerResponse.onclose (/home/trygve/Work/podium-2/podium-client/node_modules/end-of-stream/index.js:49:67)
    at emitNone (events.js:110:20)
    at ServerResponse.emit (events.js:207:7)
    at Socket.onServerResponseClose (_http_server.js:153:44)
    at emitOne (events.js:120:20)
    at Socket.emit (events.js:210:7)
    at TCP._handle.close [as _onclose] (net.js:546:12)

In node version 8.2.0 or newer the output will just be undefined.

This is due to a corrected error in node so I am not sure if this is expected behaviour. The stream are still terminated prematurely so I do kinda expect the same Error from this module in node version 8.2.0 and newer.

See also: nodejs/node#15029

@SimenB
Copy link

SimenB commented Sep 14, 2017

The change in node is being reverted (nodejs/node#15404), so this can be closed

@mafintosh
Copy link
Owner

Glad to see it fixed :)

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

3 participants