From f47eea03cc64f553fe2758ad186db70424cc557d Mon Sep 17 00:00:00 2001 From: Julien Fontanet Date: Tue, 31 Dec 2013 16:08:28 +0100 Subject: [PATCH] Do not try to connect to a server indefinitely. --- src/xapi.coffee | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/xapi.coffee b/src/xapi.coffee index 8953ec332..b7eb0bab5 100644 --- a/src/xapi.coffee +++ b/src/xapi.coffee @@ -14,6 +14,8 @@ $xmlrpc = require 'xmlrpc' # Note: All methods are synchronous (using fibers). class $XAPI + # Number of tries when the connection fails (TCP or XAPI). + tries: 10 constructor: ({@host, @username, @password}) -> @connect() @@ -45,6 +47,7 @@ class $XAPI args.unshift @sessionId if @sessionId + tries = @tries do helper = => try result = @xmlrpc.methodCall method, args @@ -59,6 +62,9 @@ class $XAPI error = result.ErrorDescription or value catch error # Captures the error if it was thrown. + # If it failed too much times, just stops. + throw error unless --@tries + # Gets the error code for transport errors and XAPI errors. code = error.code or error[0]