File tree Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Expand file tree Collapse file tree 1 file changed +12
-1
lines changed Original file line number Diff line number Diff line change @@ -153,11 +153,22 @@ TcpConnection.createConnectingConnection = function(
153
153
connection . _initSocket ( socket ) ;
154
154
if ( onConnectionEstablished ) onConnectionEstablished ( connection ) ;
155
155
} ) ;
156
+ var timer = setTimeout ( function ( ) {
157
+ log . error ( 'TcpConnection: timeout when connecting to %j in %d ms' , remoteEndPoint , connectionTimeout ) ;
158
+ connection . close ( ) ;
159
+ if ( onConnectionFailed ) onConnectionFailed ( connection , new Error ( 'Connection failed' ) ) ;
160
+ } , connectionTimeout )
156
161
socket . once ( 'error' , onError ) ;
157
162
function onError ( err ) {
163
+ clearTimeout ( timer ) ;
158
164
if ( onConnectionFailed ) onConnectionFailed ( connection , err ) ;
159
165
}
166
+ socket . once ( 'connect' , onConnect ) ;
167
+ function onConnect ( ) {
168
+ log . info ( 'TcpConnection: successfully connected to %j' , remoteEndPoint ) ;
169
+ clearTimeout ( timer ) ;
170
+ }
160
171
return connection ;
161
172
} ;
162
173
163
- module . exports = TcpConnection ;
174
+ module . exports = TcpConnection ;
You can’t perform that action at this time.
0 commit comments