@@ -86,7 +86,9 @@ RedisClient.prototype.install_stream_listeners = function() {
86
86
} ) ;
87
87
88
88
this . stream . on ( "data" , function ( buffer_from_socket ) {
89
- self . on_data ( buffer_from_socket ) ;
89
+ // The data.toString() has a significant impact on big chunks and therefor this should only be used if necessary
90
+ // debug("Net read " + this.address + " id " + this.connection_id + ": " + data.toString());
91
+ self . reply_parser . execute ( buffer_from_socket ) ;
90
92
} ) ;
91
93
92
94
this . stream . on ( "error" , function ( msg ) {
@@ -273,8 +275,18 @@ RedisClient.prototype.init_parser = function () {
273
275
this . reply_parser = new this . parser_module . Parser ( {
274
276
return_buffers : self . options . return_buffers || self . options . detect_buffers || false
275
277
} ) ;
276
- this . reply_parser . send_error = this . return_error . bind ( self ) ;
277
- this . reply_parser . send_reply = this . return_reply . bind ( self ) ;
278
+ // Important: Only send results / errors async.
279
+ // That way the result / error won't stay in a try catch block and catch user things
280
+ this . reply_parser . send_error = function ( data ) {
281
+ process . nextTick ( function ( ) {
282
+ this . return_error ( data ) ;
283
+ } . bind ( this ) ) ;
284
+ } . bind ( this ) ;
285
+ this . reply_parser . send_reply = function ( data ) {
286
+ process . nextTick ( function ( ) {
287
+ this . return_reply ( data ) ;
288
+ } . bind ( this ) ) ;
289
+ } . bind ( this ) ;
278
290
} ;
279
291
280
292
RedisClient . prototype . on_ready = function ( ) {
@@ -488,33 +500,22 @@ RedisClient.prototype.connection_gone = function (why) {
488
500
this . retry_timer = setTimeout ( retry_connection , this . retry_delay , this ) ;
489
501
} ;
490
502
491
- RedisClient . prototype . on_data = function ( data ) {
492
- // The data.toString() has a significant impact on big chunks and therefor this should only be used if necessary
493
- // debug("Net read " + this.address + " id " + this.connection_id + ": " + data.toString());
494
-
495
- try {
496
- this . reply_parser . execute ( data ) ;
497
- } catch ( err ) {
498
- // This is an unexpected parser problem, an exception that came from the parser code itself.
499
- // Parser should emit "error" events if it notices things are out of whack.
500
- // Callbacks that throw exceptions will land in return_reply(), below.
501
- // TODO - it might be nice to have a different "error" event for different types of errors
502
- this . emit ( "error" , err ) ;
503
- }
504
- } ;
505
-
506
503
RedisClient . prototype . return_error = function ( err ) {
507
504
var command_obj = this . command_queue . shift ( ) , queue_len = this . command_queue . length ;
508
- err . command_used = command_obj . command . toUpperCase ( ) ;
505
+ if ( command_obj . command && command_obj . command . toUpperCase ) {
506
+ err . command_used = command_obj . command . toUpperCase ( ) ;
507
+ }
509
508
510
509
if ( this . pub_sub_mode === false && queue_len === 0 ) {
511
510
this . command_queue = new Queue ( ) ;
512
511
this . emit ( "idle" ) ;
513
512
}
513
+
514
514
if ( this . should_buffer && queue_len <= this . command_queue_low_water ) {
515
515
this . emit ( "drain" ) ;
516
516
this . should_buffer = false ;
517
517
}
518
+
518
519
if ( command_obj . callback ) {
519
520
command_obj . callback ( err ) ;
520
521
} else {
0 commit comments