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 @@ -29,6 +29,7 @@ var tcp = require('net'),
2929
3030var crlf = "\r\n" ;
3131var crlf_len = crlf . length ;
32+ var self ;
3233
3334var error_replies = [ 'ERROR' , 'NOT_FOUND' , 'CLIENT_ERROR' , 'SERVER_ERROR' ] ;
3435
@@ -48,7 +49,7 @@ util.inherits(Client, EventEmitter);
4849Client . prototype . connect = function ( ) {
4950 if ( ! this . conn ) {
5051 this . conn = new tcp . createConnection ( this . port , this . host ) ;
51- var self = this ;
52+ self = this ;
5253 this . conn . addListener ( "connect" , function ( ) {
5354 this . setTimeout ( 0 ) ; // try to stay connected.
5455 this . setNoDelay ( ) ;
@@ -108,7 +109,12 @@ Client.prototype.dispatchHandles = function() {
108109Client . prototype . query = function ( query , type , callback ) {
109110 this . callbacks . push ( { type : type , fun : callback } ) ;
110111 this . sends ++ ;
111- this . conn . write ( query + crlf ) ;
112+ if ( this . conn !== null ) {
113+ this . conn . write ( query + crlf ) ;
114+ } else {
115+ // Server has crashed or in another way become unavailable, connection closed.
116+ self . emit ( "close" ) ;
117+ }
112118} ;
113119
114120Client . prototype . close = function ( ) {
You can’t perform that action at this time.
0 commit comments