Skip to content

Commit

Permalink
OS-1767: Fix exception handling on zone socket error
Browse files Browse the repository at this point in the history
  • Loading branch information
orlandov committed Dec 14, 2012
1 parent 6af1162 commit aed60fd
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
39 changes: 22 additions & 17 deletions src/vm/lib/metadata/agent.js
Expand Up @@ -29,16 +29,8 @@ MetadataAgent.prototype.createZoneLog = function (type, zonename) {
['info', 'debug', 'trace', 'warn', 'error', 'fatal']
.forEach(function (l) {
zlog[l] = function () {
if (l === 'debug') {
self.log[l].debug(zonename+":");
self.log[l].apply(self.log, arguments);
}
else {
self.log[l].call
( self.log
, type + ":" + zonename + " - " + arguments[0]
);
}
self.log[l].call(
self.log, type + ":" + zonename + " - " + arguments[0]);
}
});
return zlog;
Expand Down Expand Up @@ -132,7 +124,7 @@ MetadataAgent.prototype.startKVMSocketServer = function (zonename, callback) {
var self = this;
var zlog = self.createZoneLog('vm', zonename);
var zonePath = self.zones[zonename].zonepath;
var localpath = path.join('/var/run/smartdc');
var localpath = '/var/run/smartdc';
var smartdcpath = path.join(zonePath, 'root', localpath);
var sockpath = path.join(self.zones[zonename].zonepath, '/root/tmp/vm.ttyb');

Expand All @@ -144,7 +136,7 @@ MetadataAgent.prototype.startKVMSocketServer = function (zonename, callback) {
( 2000
, 120000
, function (callback) {
path.exists(sockpath, function (exists) {
fs.exists(sockpath, function (exists) {
setTimeout(function () {
callback(null, exists);
}, 1000);
Expand Down Expand Up @@ -246,7 +238,7 @@ function (zonename, checkService, callback) {
});
}
, function (callback) {
path.exists(smartdcpath, function (exists) {
fs.exists(smartdcpath, function (exists) {
if (exists) {
return callback();
}
Expand Down Expand Up @@ -295,10 +287,21 @@ MetadataAgent.prototype.createZoneSocket = function (zopts, callback) {
});

socket.on('error', function (e) {
zlog.error("Socket error");
zlog.error(e.message);
zlog.error('ZSocket error: ' + e.message);
zlog.error(e.stack);
zlog.debug(e);
zlog.info(
'Attempting to recover;'
+ ' closing and recreating zone socket and server.');
try {
server.close();
}
catch (e) {
zlog.error('Caught exception closing server: ' + e.message);
zlog.error(e.stack);
}

socket.end();
self.createZoneSocket(zopts);
});
});

Expand Down Expand Up @@ -330,7 +333,9 @@ MetadataAgent.prototype.createZoneSocket = function (zopts, callback) {
server.listen();
});

callback();
if (callback) {
callback();
}
}

MetadataAgent.prototype.makeMetadataHandler = function (zone, socket) {
Expand Down
3 changes: 2 additions & 1 deletion src/vm/lib/metadata/zone_booted_watcher.js
@@ -1,5 +1,6 @@
var execFile = require('child_process').execFile;
var path = require('path');
var fs = require('fs');

var ZoneBootedWatcher = module.exports = function (delay, allZones) {
this.delay = delay;
Expand Down Expand Up @@ -33,7 +34,7 @@ ZoneBootedWatcher.prototype.startExecutingSvcs = function () {
&& self.zones.hasOwnProperty(zone)) {

zoneObj = self.allZones[zone];
if (path.existsSync(path.join(zoneObj.zonepath,
if (fs.existsSync(path.join(zoneObj.zonepath,
'/root/tmp/.ready_for_metadata'))) {

var fn = (self.zones[zone]);
Expand Down

0 comments on commit aed60fd

Please sign in to comment.