Various updates.

This commit is contained in:
Julien Fontanet 2013-10-04 13:39:50 +02:00
parent c759df855d
commit e8b1be6568
2 changed files with 14 additions and 5 deletions

View File

@ -46,18 +46,20 @@ Xapi.prototype.call = function (method) {
}).fail(function (error) {
// Gets the error code for transport errors and XAPI errors.
var previous = current;
current = error.code || error[0];
// XAPI sommetimes close the connection when the server is
// no longer pool master (`event.next`), so we have to
// retry at least once to know who is the new pool master.
if (('ECONNRESET' === current) && (previous !== current))
if (('ECONNRESET' === current)
|| ('ECONNREFUSED' === current))
{
// @todo Does not work because it seems to reuse the
// broken socket.
// Node.js seems to reuse the broken socket, so we add
// a small delay.
return Q.delay(2000).then(helper);
// @todo Add a limit to avoid trying indefinitely.
return Q.delay(1000).then(helper);
}
//
@ -91,6 +93,11 @@ Xapi.prototype.changeHost = function (host) {
return;
}
if (this.host)
{
console.log('changing host from '+ this.host +' to '+ host);
}
this.host = host;
this.xmlrpc = xmlrpc.createSecureClient({
hostname: host,

View File

@ -335,6 +335,8 @@ Xo.prototype.start = function (cfg) {
}).fail(function (error) {
if ('SESSION_NOT_REGISTERED' === error[0])
{
console.log('registering for events on '+ xapi.host);
// We are registering for events here to
// properly handle reconnections.
return xapi.call('event.register', ['*']).then(loop);