Permalink
Browse files

OS-1767: Fix exception handling on zone socket error

  • Loading branch information...
1 parent 6af1162 commit aed60fd3858cd4a808417b9642bbd44927ee1fcb @orlandov orlandov committed Dec 14, 2012
Showing with 24 additions and 18 deletions.
  1. +22 −17 src/vm/lib/metadata/agent.js
  2. +2 −1 src/vm/lib/metadata/zone_booted_watcher.js
View
39 src/vm/lib/metadata/agent.js
@@ -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;
@@ -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');
@@ -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);
@@ -246,7 +238,7 @@ function (zonename, checkService, callback) {
});
}
, function (callback) {
- path.exists(smartdcpath, function (exists) {
+ fs.exists(smartdcpath, function (exists) {
if (exists) {
return callback();
}
@@ -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);
});
});
@@ -330,7 +333,9 @@ MetadataAgent.prototype.createZoneSocket = function (zopts, callback) {
server.listen();
});
- callback();
+ if (callback) {
+ callback();
+ }
}
MetadataAgent.prototype.makeMetadataHandler = function (zone, socket) {
View
3 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;
@@ -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]);

0 comments on commit aed60fd

Please sign in to comment.