File tree Expand file tree Collapse file tree 1 file changed +8
-2
lines changed
Expand file tree Collapse file tree 1 file changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -28,6 +28,7 @@ var tcp = require('net'),
2828
2929var crlf = "\r\n" ;
3030var crlf_len = crlf . length ;
31+ var self ;
3132
3233var error_replies = [ 'ERROR' , 'NOT_FOUND' , 'CLIENT_ERROR' , 'SERVER_ERROR' ] ;
3334
@@ -47,7 +48,7 @@ util.inherits(Client, process.EventEmitter);
4748Client . prototype . connect = function ( ) {
4849 if ( ! this . conn ) {
4950 this . conn = new tcp . createConnection ( this . port , this . host ) ;
50- var self = this ;
51+ self = this ;
5152 this . conn . addListener ( "connect" , function ( ) {
5253 this . setTimeout ( 0 ) ; // try to stay connected.
5354 this . setNoDelay ( ) ;
@@ -107,7 +108,12 @@ Client.prototype.dispatchHandles = function() {
107108Client . prototype . query = function ( query , type , callback ) {
108109 this . callbacks . push ( { type : type , fun : callback } ) ;
109110 this . sends ++ ;
110- this . conn . write ( query + crlf ) ;
111+ if ( this . conn !== null ) {
112+ this . conn . write ( query + crlf ) ;
113+ } else {
114+ // Server has crashed or in another way become unavailable, connection closed.
115+ self . emit ( "close" ) ;
116+ }
111117} ;
112118
113119Client . prototype . close = function ( ) {
You can’t perform that action at this time.
0 commit comments