@@ -151,6 +151,18 @@ function eos(stream, options, callback) {
151151 callback . call ( stream ) ;
152152 } ;
153153
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+
154166 const onrequest = ( ) => {
155167 stream . req . on ( 'finish' , onfinish ) ;
156168 } ;
@@ -186,22 +198,22 @@ function eos(stream, options, callback) {
186198 process . nextTick ( onclose ) ;
187199 } else if ( wState ?. errorEmitted || rState ?. errorEmitted ) {
188200 if ( ! willEmitClose ) {
189- process . nextTick ( onclose ) ;
201+ process . nextTick ( onclosed ) ;
190202 }
191203 } else if (
192204 ! readable &&
193205 ( ! willEmitClose || isReadable ( stream ) ) &&
194206 ( writableFinished || isWritable ( stream ) === false )
195207 ) {
196- process . nextTick ( onclose ) ;
208+ process . nextTick ( onclosed ) ;
197209 } else if (
198210 ! writable &&
199211 ( ! willEmitClose || isWritable ( stream ) ) &&
200212 ( readableFinished || isReadable ( stream ) === false )
201213 ) {
202- process . nextTick ( onclose ) ;
214+ process . nextTick ( onclosed ) ;
203215 } else if ( ( rState && stream . req && stream . aborted ) ) {
204- process . nextTick ( onclose ) ;
216+ process . nextTick ( onclosed ) ;
205217 }
206218
207219 const cleanup = ( ) => {
0 commit comments