http: buffer writes even while no socket assigned
PR-URL: https://github.com/nodejs/node/pull/29019 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
This commit is contained in:
parent
53e467db24
commit
c065773cc5
@ -23,6 +23,7 @@
|
|||||||
|
|
||||||
const { Object, ObjectPrototype } = primordials;
|
const { Object, ObjectPrototype } = primordials;
|
||||||
|
|
||||||
|
const { getDefaultHighWaterMark } = require('internal/streams/state');
|
||||||
const assert = require('internal/assert');
|
const assert = require('internal/assert');
|
||||||
const Stream = require('stream');
|
const Stream = require('stream');
|
||||||
const internalUtil = require('internal/util');
|
const internalUtil = require('internal/util');
|
||||||
@ -51,6 +52,7 @@ const {
|
|||||||
} = require('internal/errors');
|
} = require('internal/errors');
|
||||||
const { validateString } = require('internal/validators');
|
const { validateString } = require('internal/validators');
|
||||||
|
|
||||||
|
const HIGH_WATER_MARK = getDefaultHighWaterMark();
|
||||||
const { CRLF, debug } = common;
|
const { CRLF, debug } = common;
|
||||||
|
|
||||||
const kIsCorked = Symbol('isCorked');
|
const kIsCorked = Symbol('isCorked');
|
||||||
@ -277,7 +279,7 @@ function _writeRaw(data, encoding, callback) {
|
|||||||
this.outputData.push({ data, encoding, callback });
|
this.outputData.push({ data, encoding, callback });
|
||||||
this.outputSize += data.length;
|
this.outputSize += data.length;
|
||||||
this._onPendingData(data.length);
|
this._onPendingData(data.length);
|
||||||
return false;
|
return this.outputSize < HIGH_WATER_MARK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -9,6 +9,10 @@ function highWaterMarkFrom(options, isDuplex, duplexKey) {
|
|||||||
isDuplex ? options[duplexKey] : null;
|
isDuplex ? options[duplexKey] : null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getDefaultHighWaterMark(objectMode) {
|
||||||
|
return objectMode ? 16 : 16 * 1024;
|
||||||
|
}
|
||||||
|
|
||||||
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
||||||
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
|
||||||
if (hwm != null) {
|
if (hwm != null) {
|
||||||
@ -20,9 +24,10 @@ function getHighWaterMark(state, options, duplexKey, isDuplex) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Default value
|
// Default value
|
||||||
return state.objectMode ? 16 : 16 * 1024;
|
return getDefaultHighWaterMark(state.objectMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
getHighWaterMark
|
getHighWaterMark,
|
||||||
|
getDefaultHighWaterMark
|
||||||
};
|
};
|
||||||
|
19
test/parallel/test-http-outgoing-buffer.js
Normal file
19
test/parallel/test-http-outgoing-buffer.js
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
// Flags: --expose-internals
|
||||||
|
'use strict';
|
||||||
|
require('../common');
|
||||||
|
const assert = require('assert');
|
||||||
|
const { getDefaultHighWaterMark } = require('internal/streams/state');
|
||||||
|
|
||||||
|
const http = require('http');
|
||||||
|
const OutgoingMessage = http.OutgoingMessage;
|
||||||
|
|
||||||
|
const msg = new OutgoingMessage();
|
||||||
|
msg._implicitHeader = function() {};
|
||||||
|
|
||||||
|
// Writes should be buffered until highwatermark
|
||||||
|
// even when no socket is assigned.
|
||||||
|
|
||||||
|
assert.strictEqual(msg.write('asd'), true);
|
||||||
|
while (msg.write('asd'));
|
||||||
|
const highwatermark = msg.writableHighWaterMark || getDefaultHighWaterMark();
|
||||||
|
assert(msg.outputSize >= highwatermark);
|
Loading…
x
Reference in New Issue
Block a user