0

We recently converted a web site to web application. Everything works perfectly when we deploy. If we allow the application to shut down (i.e. no one uses it for 1 hr), then when we go back to it, the Login page loads fine, but then calls to Web Services (old SOAP services) fail. This does not repro in dev environment, only on our servers.

Where we tracked some issues down, it appears that one or more strings were not initialized before they were used, resulting in empty or null strings that blow things up.

One thing that really pains us is that Log4Net logging stops totally; so tracking down issues require significant kludging code.

Any idea of the root cause (and hopefully a fix)

========UPDATE=========

One of the issue tracked down to an interesting situation…

The service call that failed produced "It must at least specify the Client property." This is set by this

profile.Client = ApplicationName;

public static string ApplicationName
{ 
  get 
  {
     return string.Format(CLIENTNAME, Resources.AppVersion.Version);
  }
}

Which calls:

internal static string Version 
{
    get 
    {
        return ResourceManager.GetString("Version", resourceCulture);
    }
}

Conceptually, it should never fail if it worked once.

Another issue was Log4net not working when the web application reloads, where we also encountered static

    private static readonly ILog ExceptionLog = LogManager.GetLogger("ExceptionLogger");
    private static readonly ILog SoaLog = LogManager.GetLogger("soaPerfLogger");
    private static readonly ILog InfoLog = LogManager.GetLogger("InfoLogger");
    private static readonly ILog DebugLog = LogManager.GetLogger("DebugLogger");

The apparent cause seems to be static variables nulling on the restart of the Web Application. They are not being reinitialized.

Awaiting brilliant suggestions! Otherwise, I will be slugging thru all of the 852 static usages in the code to add code to address this unusual behavior.

Anand
  • 14,545
  • 8
  • 32
  • 44

2 Answers2

1

Are there any dependencies among your static fields, e.g. expecting them to be initialized in a certain order? If your class does not have a static constructor there is no guarantee of the order in which they will be initialized. I always make sure to include a static constructor when using static fields, and generally do my initialization there instead of using field intializers. See the C# language specification on static field initialization.

I might also look at granadaCoder's suggestion and make them instance fields of a Singleton if that won't be too painful.

What version of IIS is this application running on?

0

Ken,

I have been badly bitten by static members in asp.net as they are shared across multiple asp.net threads. (Static methods are fine.) I don't know if that is possibly related to your issue but can you make those instance based? If their initialization is expensive, consider storing them as Application variables in App Start or possibly in Cache.

Is there possibly more than a single request hitting your application on startup? If your initialization is long running, does thread / request number one start populating values while thread / request #2 come along and re-initialize values to null?

That said, I am no threading expert but can tell you a great story about a code review / troubleshooting exercise I participated in years ago that turned out to be this exact issue. The client had thousands of requests occurring in short order and some were overwriting the static data populated by other requests (and students were being registered for the wrong classes.) They had been chasing the issue for weeks and after living through someone else's nightmare, I avoid static members in web applications.

andleer
  • 22,388
  • 8
  • 62
  • 82