Skip to content

Commit 8c276ca

Browse files
committed
http: fix chunked write coalescing CI failures
1 parent 1ce49dd commit 8c276ca

3 files changed

Lines changed: 10 additions & 16 deletions

File tree

lib/_http_outgoing.js

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -328,21 +328,18 @@ OutgoingMessage.prototype.uncork = function uncork() {
328328
}
329329
assert(this.chunkedEncoding);
330330

331-
let callbacks;
331+
const callbacks = [];
332332
this._send(len.toString(16), 'latin1', null);
333333
this._send(crlf_buf, null, null);
334334
for (let n = 0; n < buf.length; n += 3) {
335335
this._send(buf[n + 0], buf[n + 1], null);
336-
if (buf[n + 2]) {
337-
callbacks ??= [];
338-
callbacks.push(buf[n + 2]);
339-
}
336+
callbacks.push(buf[n + 2]);
340337
}
341-
this._send(crlf_buf, null, callbacks.length ? (err) => {
338+
this._send(crlf_buf, null, (err) => {
342339
for (const callback of callbacks) {
343340
callback(err);
344341
}
345-
} : null);
342+
});
346343

347344
this[kChunkedBuffer].length = 0;
348345
this[kChunkedLength] = 0;
@@ -1033,7 +1030,7 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
10331030

10341031
if (!fromEnd && msg.socket && !msg.socket.writableCorked) {
10351032
msg.cork();
1036-
process.nextTick(connectionCorkNT, msg, msg.socket);
1033+
process.nextTick(connectionCorkNT, msg);
10371034
}
10381035

10391036
let ret;
@@ -1083,13 +1080,10 @@ function maybePrepareFinalChunk(msg, chunk, encoding) {
10831080
return !!msg._header && msg._hasBody && !msg.chunkedEncoding;
10841081
}
10851082

1086-
function connectionCorkNT(msg, conn) {
1083+
function connectionCorkNT(msg) {
10871084
if (msg[kCorked]) {
10881085
msg.uncork();
10891086
}
1090-
if (msg[kSocket] !== conn) {
1091-
conn.uncork();
1092-
}
10931087
}
10941088

10951089
OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {

test/parallel/test-http-byteswritten.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,10 @@ const httpServer = http.createServer(common.mustCall(function(req, res) {
4444
res.write(bchunk);
4545
res.write(chunk, 'hex');
4646
}
47-
// Get .bytesWritten while buffer is not empty
48-
assert(res.connection.bytesWritten > 0);
49-
5047
res.end(body);
48+
49+
// Get .bytesWritten while the socket buffer is not empty.
50+
assert(res.connection.bytesWritten > 0);
5151
}));
5252

5353
httpServer.listen(0, function() {

test/parallel/test-webstreams-pipeline.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ const http = require('http');
212212
values.push(chunk?.toString());
213213
});
214214
res.on('end', common.mustCall(() => {
215-
assert.deepStrictEqual(values, ['hello', 'world']);
215+
assert.strictEqual(values.join(''), 'helloworld');
216216
server.close();
217217
}));
218218
}));

0 commit comments

Comments
 (0)