@@ -151,6 +151,18 @@ function eos(stream, options, callback) {
151
151
callback . call ( stream ) ;
152
152
} ;
153
153
154
+ const onclosed = ( ) => {
155
+ closed = true ;
156
+
157
+ const errored = isWritableErrored ( stream ) || isReadableErrored ( stream ) ;
158
+
159
+ if ( errored && typeof errored !== 'boolean' ) {
160
+ return callback . call ( stream , errored ) ;
161
+ }
162
+
163
+ callback . call ( stream ) ;
164
+ } ;
165
+
154
166
const onrequest = ( ) => {
155
167
stream . req . on ( 'finish' , onfinish ) ;
156
168
} ;
@@ -186,22 +198,22 @@ function eos(stream, options, callback) {
186
198
process . nextTick ( onclose ) ;
187
199
} else if ( wState ?. errorEmitted || rState ?. errorEmitted ) {
188
200
if ( ! willEmitClose ) {
189
- process . nextTick ( onclose ) ;
201
+ process . nextTick ( onclosed ) ;
190
202
}
191
203
} else if (
192
204
! readable &&
193
205
( ! willEmitClose || isReadable ( stream ) ) &&
194
206
( writableFinished || isWritable ( stream ) === false )
195
207
) {
196
- process . nextTick ( onclose ) ;
208
+ process . nextTick ( onclosed ) ;
197
209
} else if (
198
210
! writable &&
199
211
( ! willEmitClose || isWritable ( stream ) ) &&
200
212
( readableFinished || isReadable ( stream ) === false )
201
213
) {
202
- process . nextTick ( onclose ) ;
214
+ process . nextTick ( onclosed ) ;
203
215
} else if ( ( rState && stream . req && stream . aborted ) ) {
204
- process . nextTick ( onclose ) ;
216
+ process . nextTick ( onclosed ) ;
205
217
}
206
218
207
219
const cleanup = ( ) => {
0 commit comments