Skip to content

Commit 64cc917

Browse files
committed
http: cleanup cork logic
1 parent ca2f874 commit 64cc917

File tree

1 file changed

+11
-8
lines changed

1 file changed

+11
-8
lines changed

lib/_http_outgoing.js

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
211211
ObjectDefineProperty(OutgoingMessage.prototype, 'writableCorked', {
212212
__proto__: null,
213213
get() {
214-
return this[kCorked];
214+
return this[kSocket] ? this[kSocket].writableCorked : this[kCorked];
215215
},
216216
});
217217

@@ -252,6 +252,9 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'socket', {
252252
return this[kSocket];
253253
},
254254
set: function(val) {
255+
for (let n = 0; n < this[kCorked]; n++) {
256+
val?.cork();
257+
}
255258
for (let n = 0; n < this[kCorked]; n++) {
256259
val?.cork();
257260
this[kSocket]?.uncork();
@@ -1000,9 +1003,9 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
10001003
}
10011004
}
10021005

1003-
if (!fromEnd && msg.socket && !msg.socket.writableCorked) {
1004-
msg.socket.cork();
1005-
process.nextTick(connectionCorkNT, msg.socket);
1006+
if (!fromEnd && !msg.writableCorked) {
1007+
msg.cork();
1008+
process.nextTick(connectionUncorkNT, msg);
10061009
}
10071010

10081011
let ret;
@@ -1027,8 +1030,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
10271030
}
10281031

10291032

1030-
function connectionCorkNT(conn) {
1031-
conn.uncork();
1033+
function connectionUncorkNT(msg) {
1034+
msg.uncork();
10321035
}
10331036

10341037
OutgoingMessage.prototype.addTrailers = function addTrailers(headers) {
@@ -1143,9 +1146,9 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
11431146
// Fully uncork connection on end().
11441147
this[kSocket]._writableState.corked = 1;
11451148
this[kSocket].uncork();
1149+
} else {
1150+
this[kCorked] = 0;
11461151
}
1147-
this[kCorked] = 1;
1148-
this.uncork();
11491152

11501153
this.finished = true;
11511154

0 commit comments

Comments
 (0)