@@ -111,6 +111,7 @@ const {
111111 startPerf,
112112 stopPerf,
113113} = require ( 'internal/perf/observe' ) ;
114+ const FixedQueue = require ( 'internal/fixed_queue' ) ;
114115
115116const STATUS_CODES = {
116117 100 : 'Continue' , // RFC 7231 6.2.1
@@ -724,7 +725,7 @@ function connectionListenerInternal(server, socket) {
724725 onClose : null ,
725726 onDrain : null ,
726727 outgoing : [ ] ,
727- incoming : [ ] ,
728+ incoming : new FixedQueue ( ) ,
728729 // `outgoingData` is an approximate amount of bytes queued through all
729730 // inactive responses. If more data than the high watermark is queued - we
730731 // need to pause TCP socket/HTTP parser, and wait until the data will be
@@ -822,7 +823,7 @@ function socketOnClose(socket, state) {
822823}
823824
824825function abortIncoming ( incoming ) {
825- while ( incoming . length ) {
826+ while ( ! incoming . isEmpty ( ) ) {
826827 const req = incoming . shift ( ) ;
827828 req . destroy ( new ConnResetException ( 'aborted' ) ) ;
828829 }
@@ -1003,15 +1004,15 @@ function resOnFinish(req, res, socket, state, server) {
10031004 } ) ;
10041005 }
10051006
1007+ const head = state . incoming . shift ( ) ;
1008+
10061009 // Usually the first incoming element should be our request. it may
10071010 // be that in the case abortIncoming() was called that the incoming
10081011 // array will be empty.
1009- if ( state . incoming . length > 0 && state . incoming [ 0 ] !== req ) {
1012+ if ( head !== null && head !== req ) {
10101013 throw new Error ( 'Out of order response finish' ) ;
10111014 }
10121015
1013- state . incoming . shift ( ) ;
1014-
10151016 // If the user never called req.read(), and didn't pipe() or
10161017 // .resume() or .on('data'), then we call req._dump() so that the
10171018 // bytes will be pulled off the wire.
0 commit comments