@@ -90,6 +90,7 @@ const kBytesWritten = Symbol('kBytesWritten');
90
90
const kErrored = Symbol ( 'errored' ) ;
91
91
const kHighWaterMark = Symbol ( 'kHighWaterMark' ) ;
92
92
const kRejectNonStandardBodyWrites = Symbol ( 'kRejectNonStandardBodyWrites' ) ;
93
+ const kSocket = Symbol ( 'kSocket' ) ;
93
94
94
95
const nop = ( ) => { } ;
95
96
@@ -211,8 +212,8 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'writableHighWaterMark', {
211
212
ObjectDefineProperty ( OutgoingMessage . prototype , 'writableCorked' , {
212
213
__proto__ : null ,
213
214
get ( ) {
214
- return this [ kCorked ] ;
215
- } ,
215
+ return this [ kSocket ] ? this [ kSocket ] . writableCorked : this [ kCorked ] ;
216
+ }
216
217
} ) ;
217
218
218
219
ObjectDefineProperty ( OutgoingMessage . prototype , '_headers' , {
@@ -260,6 +261,20 @@ ObjectDefineProperty(OutgoingMessage.prototype, 'socket', {
260
261
} ,
261
262
} ) ;
262
263
264
+ ObjectDefineProperty ( OutgoingMessage . prototype , 'socket' , {
265
+ __proto__ : null ,
266
+ get : function ( ) {
267
+ return this [ kSocket ] ;
268
+ } ,
269
+ set : function ( val ) {
270
+ for ( let n = 0 ; n < this [ kCorked ] ; n ++ ) {
271
+ val ?. cork ( ) ;
272
+ }
273
+ this [ kCorked ] = 0 ;
274
+ this [ kSocket ] = val ;
275
+ }
276
+ } ) ;
277
+
263
278
ObjectDefineProperty ( OutgoingMessage . prototype , '_headerNames' , {
264
279
__proto__ : null ,
265
280
get : internalUtil . deprecate ( function ( ) {
@@ -1000,9 +1015,9 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
1000
1015
}
1001
1016
}
1002
1017
1003
- if ( ! fromEnd && msg . socket && ! msg . socket . writableCorked ) {
1004
- msg . socket . cork ( ) ;
1005
- process . nextTick ( connectionCorkNT , msg . socket ) ;
1018
+ if ( ! fromEnd && ! msg . writableCorked ) {
1019
+ msg . cork ( ) ;
1020
+ process . nextTick ( connectionUncorkNT , msg ) ;
1006
1021
}
1007
1022
1008
1023
let ret ;
@@ -1027,8 +1042,8 @@ function write_(msg, chunk, encoding, callback, fromEnd) {
1027
1042
}
1028
1043
1029
1044
1030
- function connectionCorkNT ( conn ) {
1031
- conn . uncork ( ) ;
1045
+ function connectionUncorkNT ( msg ) {
1046
+ msg . uncork ( ) ;
1032
1047
}
1033
1048
1034
1049
OutgoingMessage . prototype . addTrailers = function addTrailers ( headers ) {
@@ -1143,9 +1158,9 @@ OutgoingMessage.prototype.end = function end(chunk, encoding, callback) {
1143
1158
// Fully uncork connection on end().
1144
1159
this [ kSocket ] . _writableState . corked = 1 ;
1145
1160
this [ kSocket ] . uncork ( ) ;
1161
+ } else {
1162
+ this [ kCorked ] = 0 ;
1146
1163
}
1147
- this [ kCorked ] = 1 ;
1148
- this . uncork ( ) ;
1149
1164
1150
1165
this . finished = true ;
1151
1166
0 commit comments