2017-01-03 21:16:48 +00:00
|
|
|
// Copyright Joyent, Inc. and other Node contributors.
|
|
|
|
//
|
|
|
|
// Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
// copy of this software and associated documentation files (the
|
|
|
|
// "Software"), to deal in the Software without restriction, including
|
|
|
|
// without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
// distribute, sublicense, and/or sell copies of the Software, and to permit
|
|
|
|
// persons to whom the Software is furnished to do so, subject to the
|
|
|
|
// following conditions:
|
|
|
|
//
|
|
|
|
// The above copyright notice and this permission notice shall be included
|
|
|
|
// in all copies or substantial portions of the Software.
|
|
|
|
//
|
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
// OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
|
|
|
|
// NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
|
|
|
|
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
|
|
|
|
// OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
|
|
|
|
// USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
2015-05-19 11:00:06 +00:00
|
|
|
'use strict';
|
2016-12-01 20:23:55 +00:00
|
|
|
const common = require('../common');
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
|
2017-06-30 23:29:09 +00:00
|
|
|
if (!common.hasCrypto)
|
2016-05-11 19:34:52 +00:00
|
|
|
common.skip('missing crypto');
|
2016-12-11 05:12:58 +00:00
|
|
|
|
|
|
|
const assert = require('assert');
|
2017-10-06 17:01:16 +00:00
|
|
|
const fixtures = require('../common/fixtures');
|
2016-12-01 20:23:55 +00:00
|
|
|
const https = require('https');
|
2015-03-04 01:11:21 +00:00
|
|
|
|
2017-10-06 17:01:16 +00:00
|
|
|
const key = fixtures.readKey('agent1-key.pem');
|
|
|
|
const cert = fixtures.readKey('agent1-cert.pem');
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
|
2018-12-10 12:27:32 +00:00
|
|
|
// Number of bytes discovered empirically to trigger the bug
|
2016-12-11 05:12:58 +00:00
|
|
|
const data = Buffer.alloc(1024 * 32 + 1);
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
|
|
|
|
httpsTest();
|
|
|
|
|
|
|
|
function httpsTest() {
|
2018-01-11 18:03:58 +00:00
|
|
|
const sopt = { key, cert };
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
|
2016-12-01 20:23:55 +00:00
|
|
|
const server = https.createServer(sopt, function(req, res) {
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
res.setHeader('content-length', data.length);
|
|
|
|
res.end(data);
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
|
2016-05-29 07:06:56 +00:00
|
|
|
server.listen(0, function() {
|
2016-12-01 20:23:55 +00:00
|
|
|
const opts = { port: this.address().port, rejectUnauthorized: false };
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
https.get(opts).on('response', function(res) {
|
|
|
|
test(res);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-12-11 05:12:58 +00:00
|
|
|
const test = common.mustCall(function(res) {
|
|
|
|
res.on('end', common.mustCall(function() {
|
2017-05-05 12:42:21 +00:00
|
|
|
assert.strictEqual(res.readableLength, 0);
|
2016-12-01 20:23:55 +00:00
|
|
|
assert.strictEqual(bytes, data.length);
|
2016-12-11 05:12:58 +00:00
|
|
|
}));
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
|
|
|
|
// Pause and then resume on each chunk, to ensure that there will be
|
|
|
|
// a lone byte hanging out at the very end.
|
2016-12-01 20:23:55 +00:00
|
|
|
let bytes = 0;
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
res.on('data', function(chunk) {
|
|
|
|
bytes += chunk.length;
|
|
|
|
this.pause();
|
2017-11-22 15:41:30 +00:00
|
|
|
setTimeout(() => { this.resume(); }, 1);
|
http client: pull last chunk on socket close
When the socket closes, the client's http incoming message object was
emitting an 'aborted' event if it had not yet been ended.
However, it's possible, when a response is being repeatedly paused and
resumed (eg, if piped to a slow FS write stream), that there will be a
final chunk remaining in the js-land buffer when the socket is torn
down.
When that happens, the socketCloseListener function detects that we have
not yet reached the end of the response message data, and treats this as
an abrupt abort, immediately (and forcibly) ending the incoming message
data stream, and discarding that final chunk of data.
The result is that, for example, npm will have problems because tarballs
are missing a few bytes off the end, every time.
Closes GH-6402
2013-10-23 20:08:06 +00:00
|
|
|
});
|
2016-12-11 05:12:58 +00:00
|
|
|
});
|