@@ -30,7 +30,7 @@ class Query extends Command {
30
30
this . _receivedFieldsCount = 0 ;
31
31
this . _resultIndex = 0 ;
32
32
this . _localStream = null ;
33
- this . _unpipeStream = function ( ) { } ;
33
+ this . _unpipeStream = function ( ) { } ;
34
34
this . _streamFactory = options . infileStreamFactory ;
35
35
this . _connection = null ;
36
36
}
@@ -155,7 +155,7 @@ class Query extends Command {
155
155
const onPause = ( ) => {
156
156
this . _localStream . pause ( ) ;
157
157
} ;
158
- const onData = function ( data ) {
158
+ const onData = function ( data ) {
159
159
const dataWithHeader = Buffer . allocUnsafe ( data . length + 4 ) ;
160
160
data . copy ( dataWithHeader , 4 ) ;
161
161
connection . writePacket (
@@ -227,7 +227,7 @@ class Query extends Command {
227
227
}
228
228
229
229
/* eslint no-unused-vars: ["error", { "argsIgnorePattern": "^_" }] */
230
- row ( packet , _connection ) {
230
+ row ( packet , _connection ) {
231
231
if ( packet . isEOF ( ) ) {
232
232
const status = packet . eofStatusFlags ( ) ;
233
233
const moreResults = status & ServerStatus . SERVER_MORE_RESULTS_EXISTS ;
@@ -279,11 +279,13 @@ class Query extends Command {
279
279
} ) ;
280
280
this . on ( 'end' , ( ) => {
281
281
stream . push ( null ) ; // pushing null, indicating EOF
282
- setImmediate ( ( ) => stream . emit ( 'close' ) ) ; // notify readers that query has completed
283
282
} ) ;
284
283
this . on ( 'fields' , fields => {
285
284
stream . emit ( 'fields' , fields ) ; // replicate old emitter
286
285
} ) ;
286
+ stream . on ( 'end' , ( ) => {
287
+ stream . emit ( 'close' ) ;
288
+ } ) ;
287
289
return stream ;
288
290
}
289
291
@@ -302,7 +304,7 @@ class Query extends Command {
302
304
Timers . clearTimeout ( this . queryTimeout ) ;
303
305
this . queryTimeout = null ;
304
306
}
305
-
307
+
306
308
const err = new Error ( 'Query inactivity timeout' ) ;
307
309
err . errorno = 'PROTOCOL_SEQUENCE_TIMEOUT' ;
308
310
err . code = 'PROTOCOL_SEQUENCE_TIMEOUT' ;
0 commit comments