Compulim
Compulim

Reputation: 1168

Azure Worker Role restarted after receiving "changing" + "changed" event on Node.js

I am running a simple Node.js app in Azure Worker Role, with azure-sdk-for-node package.

var azure = require('azure'),
    http = require('http'),
    winston = require('winston'),
    logger = new (winston.Logger)({
        transports: [ new (winston.transports.File)({ filename: 'C:\\log.txt' }) ]
    }),

http.createServer(function (req, res) {
    res.writeHead(200);
    res.end('Hello, World!');
}).listen(process.env.port || 1337);

azure.RoleEnvironment.on('changing', function (changes) {
    winston.info('changing', changes);

    // Got configuration changes here
    // {
    //   "changes": [
    //     {
    //       "type": "ConfigurationSettingChange",
    //       "name": "MyApp.Settings1"
    //     },
    //     {
    //       "type": "ConfigurationSettingChange",
    //       "name": "Microsoft.WindowsAzure.Plugins.RemoteAccess.AccountExpiration"
    //     }
    //   ]
    // }
});

azure.RoleEnvironment.on('changed', function () {
    // Also got this event
    winston.info('changing');
});

azure.RoleEnvironment.on('stopping', function () {
    // Never fired
    winston.info('stopping');
});

The app runs fine on Worker Role without issues, until I modify the configuration thru Management Portal.

I updated the configuration thru Management Portal and clicked Save. Shortly after that, I got both changing and changed events on the app. But 6 minutes after receiving those events, the whole Worker Role was rebooted without any stopping events. I used package winston to log to C:\ and the log persisted thru the reboot.

The log shows something like this:

00:00 setup_worker.cmd
00:01 server.js with PID 1
00:06 "role changing"
00:06 "role changed"
00:12 setup_worker.cmd
00:13 server.js with PID 2

(Note: setup_worker.cmd is the startup script in CSDEF, server.js is my app)

Although there are no stopping events after configuration change, I got the stopping event if I manually reboot the instance thru Management Portal.

So there are few questions:

  1. Why the role is rebooted after configuration change?
  2. How to prevent the role get rebooted after configuration change?
  3. Why there are no stopping events when the role get rebooted by configuration change?

Thanks!

Upvotes: 2

Views: 679

Answers (1)

Igorek
Igorek

Reputation: 15850

  1. Azure assumes that you want your servers rebooted after config changed, so that new settings can take effect properly. It does not know if you keep reading your configuration settings during runtime or only at startup. It also assumed that you have 2+ servers deployed in your Role and rebooting them one at a time will not harm you website

  2. So, I'm not familiar with node.js, however, in .NET we can watch for RoleEnvironment.Changing event, trap it and ignore the reboot on it. Check this article out: http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.changing.aspx Can you do something similar with your function delegate after you trap the changing event?

  3. I believe Stopping events only apply when you shut the role down/stop it. http://msdn.microsoft.com/en-us/library/microsoft.windowsazure.serviceruntime.roleenvironment.stopping.aspx

Upvotes: 1

Related Questions