Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c396b2a

Browse filesBrowse files
ronagtargos
authored andcommitted
http: buffer writes even while no socket assigned
PR-URL: #29019 Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com>
1 parent 6bc4620 commit c396b2a
Copy full SHA for c396b2a

File tree

Expand file treeCollapse file tree

3 files changed

+29
-3
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

3 files changed

+29
-3
lines changed
Open diff view settings
Collapse file

‎lib/_http_outgoing.js‎

Copy file name to clipboardExpand all lines: lib/_http_outgoing.js
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323

2424
const { Object, ObjectPrototype } = primordials;
2525

26+
const { getDefaultHighWaterMark } = require('internal/streams/state');
2627
const assert = require('internal/assert');
2728
const Stream = require('stream');
2829
const internalUtil = require('internal/util');
@@ -51,6 +52,7 @@ const {
5152
} = require('internal/errors');
5253
const { validateString } = require('internal/validators');
5354

55+
const HIGH_WATER_MARK = getDefaultHighWaterMark();
5456
const { CRLF, debug } = common;
5557

5658
const kIsCorked = Symbol('isCorked');
@@ -277,7 +279,7 @@ function _writeRaw(data, encoding, callback) {
277279
this.outputData.push({ data, encoding, callback });
278280
this.outputSize += data.length;
279281
this._onPendingData(data.length);
280-
return false;
282+
return this.outputSize < HIGH_WATER_MARK;
281283
}
282284

283285

Collapse file

‎lib/internal/streams/state.js‎

Copy file name to clipboardExpand all lines: lib/internal/streams/state.js
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ function highWaterMarkFrom(options, isDuplex, duplexKey) {
99
isDuplex ? options[duplexKey] : null;
1010
}
1111

12+
function getDefaultHighWaterMark(objectMode) {
13+
return objectMode ? 16 : 16 * 1024;
14+
}
15+
1216
function getHighWaterMark(state, options, duplexKey, isDuplex) {
1317
const hwm = highWaterMarkFrom(options, isDuplex, duplexKey);
1418
if (hwm != null) {
@@ -20,9 +24,10 @@ function getHighWaterMark(state, options, duplexKey, isDuplex) {
2024
}
2125

2226
// Default value
23-
return state.objectMode ? 16 : 16 * 1024;
27+
return getDefaultHighWaterMark(state.objectMode);
2428
}
2529

2630
module.exports = {
27-
getHighWaterMark
31+
getHighWaterMark,
32+
getDefaultHighWaterMark
2833
};
Collapse file
+19Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Flags: --expose-internals
2+
'use strict';
3+
require('../common');
4+
const assert = require('assert');
5+
const { getDefaultHighWaterMark } = require('internal/streams/state');
6+
7+
const http = require('http');
8+
const OutgoingMessage = http.OutgoingMessage;
9+
10+
const msg = new OutgoingMessage();
11+
msg._implicitHeader = function() {};
12+
13+
// Writes should be buffered until highwatermark
14+
// even when no socket is assigned.
15+
16+
assert.strictEqual(msg.write('asd'), true);
17+
while (msg.write('asd'));
18+
const highwatermark = msg.writableHighWaterMark || getDefaultHighWaterMark();
19+
assert(msg.outputSize >= highwatermark);

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.