Why is Stopping/OnStop not called when scaling in in Azure? -


roleenvironment.stopping/roleentrypoint.onstop() not called dying instances when reduce role instance count. are called when instance rebooted or deployment stopped. doing wrong, or not supposed need clean in case?

i have simple worker role (vs2012 update 1, default cloud project 1 worker role, added smarx's table storage trace listener). code here; no other dependencies:

using system; using system.collections.generic; using system.data.services.client; using system.diagnostics; using system.linq; using system.net; using system.threading; using microsoft.windowsazure; using microsoft.windowsazure.diagnostics; using microsoft.windowsazure.serviceruntime; using microsoft.windowsazure.storageclient;  namespace workerrole1 {     public class workerrole : roleentrypoint     {         bool shouldrun = true;         eventwaithandle runfinished = new eventwaithandle(true, eventresetmode.manualreset);          public override bool onstart()         {             servicepointmanager.defaultconnectionlimit = 12;             roleenvironment.stopping += (object sender, roleenvironmentstoppingeventargs e) => {                 trace.writeline("workerrole1 stopping called", "information");                 shouldrun = false;             };             return base.onstart();         }          public override void run()         {             runfinished.reset();             try {                 trace.writeline("workerrole1 entry point called", "information");                 while (shouldrun) {                     thread.sleep(10000);                     trace.writeline("working", "information");                 }                 trace.writeline("finished", "information");             } {                 runfinished.set();             }         }          public override void onstop()         {             trace.writeline("onstop: waiting run() finish", "information");             runfinished.waitone();             trace.writeline("onstop: run() finished", "information");             base.onstop();         }     }      public class logmessage : tableserviceentity     {         public datetime time { get; set; }         public string message { get; set; }         public string instanceid { get; set; }         public string category { get; set; }          public logmessage() { }         public logmessage(string message, string category)         {             message = message;             category = category;             time = datetime.utcnow;             instanceid = roleenvironment.currentroleinstance.id;             partitionkey = roleenvironment.deploymentid;             rowkey = (datetime.maxvalue.ticks - time.ticks).tostring("d19");         }     }      public class tabletracelistener : tracelistener     {         private tableservicecontext _context = null;         private tableservicecontext context         {                         {                 if (_context == null) {                     var tables = cloudstorageaccount                         .parse(roleenvironment.getconfigurationsettingvalue(                             attributes["connectionstringname"] ?? "dataconnectionstring"))                         .createcloudtableclient();                     tables.createtableifnotexist("log");                     _context = tables.getdataservicecontext();                     _context.mergeoption = mergeoption.notracking;                 }                 return _context;             }         }          protected override string[] getsupportedattributes() { return new[] { "connectionstringname" }; }          public override void write(string message, string category)         {             context.addobject("log", new logmessage(message, category));             context.savechangeswithretries();         }          public override void writeline(string message, string category) { write(message + "\n", category); }         public override void write(string message) { write(message, null); }         public override void writeline(string message) { write(message + "\n"); }     } } 

from experimenting, appears fabric controller removes role ips dynamic whitelist of db server during role scale down operations (before role removed).

if cause of problem, possible workaround manually add ip range 0.0.0.0-255.255.255.255 db server's whitelist (at expense of security). or re-architect application write data/messages queues instead of db during onstop (for worker role copy db later).


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -