@@ -30,7 +30,7 @@ class Query extends Command {
3030 this . _receivedFieldsCount = 0 ;
3131 this . _resultIndex = 0 ;
3232 this . _localStream = null ;
33- this . _unpipeStream = function ( ) { } ;
33+ this . _unpipeStream = function ( ) { } ;
3434 this . _streamFactory = options . infileStreamFactory ;
3535 this . _connection = null ;
3636 }
@@ -155,7 +155,7 @@ class Query extends Command {
155155 const onPause = ( ) => {
156156 this . _localStream . pause ( ) ;
157157 } ;
158- const onData = function ( data ) {
158+ const onData = function ( data ) {
159159 const dataWithHeader = Buffer . allocUnsafe ( data . length + 4 ) ;
160160 data . copy ( dataWithHeader , 4 ) ;
161161 connection . writePacket (
@@ -227,7 +227,7 @@ class Query extends Command {
227227 }
228228
229229 /* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
230- row ( packet , _connection ) {
230+ row ( packet , _connection ) {
231231 if ( packet . isEOF ( ) ) {
232232 const status = packet . eofStatusFlags ( ) ;
233233 const moreResults = status & ServerStatus . SERVER_MORE_RESULTS_EXISTS ;
@@ -279,11 +279,13 @@ class Query extends Command {
279279 } ) ;
280280 this . on ( 'end' , ( ) => {
281281 stream . push ( null ) ; // pushing null, indicating EOF
282- setImmediate ( ( ) => stream . emit ( 'close' ) ) ; // notify readers that query has completed
283282 } ) ;
284283 this . on ( 'fields' , fields => {
285284 stream . emit ( 'fields' , fields ) ; // replicate old emitter
286285 } ) ;
286+ stream . on ( 'end' , ( ) => {
287+ stream . emit ( 'close' ) ;
288+ } ) ;
287289 return stream ;
288290 }
289291
@@ -302,7 +304,7 @@ class Query extends Command {
302304 Timers . clearTimeout ( this . queryTimeout ) ;
303305 this . queryTimeout = null ;
304306 }
305-
307+
306308 const err = new Error ( 'Query inactivity timeout' ) ;
307309 err . errorno = 'PROTOCOL_SEQUENCE_TIMEOUT' ;
308310 err . code = 'PROTOCOL_SEQUENCE_TIMEOUT' ;
0 commit comments