Tricky Problems & Solutions (RSS)

Random session timeout after 5 minutes

For some time now, we have experinced some strange random timeout problems on various web applications. We have a load balanced environment with up to 6 web servers sitting behind a rather nice load balancer.

In our web applications, session timout is set at the standard 20 minutes. It is also set at 20 minutes in IIS, so everything should work fine.
However, what we have been finding is that on, what looks like a random basis, the session has timed out. Sometimes it's 20 minutes, othertimes it's 5 minutes. The first thing that we looked at was the application pool behaviour to see if the application pool was re-cycling early and kicking the sessions.
It wasn't
However, when we tried to relpicate, we could never relicate it when we went directly to one of the web servers, and sometimes replicate it when we went via the load balancer.

The load balancer was therefore the problem. The load balancer used sticky concurrent sessions, so we shouldn't experience problems. However, sticky concurrency comes with a timeout of 5 minutes. This meant that the following would happen:
  • User would come in via load balancer and be assigned to web server 1
  • User would leave browser open and idle for over 5 minutes, but under 20 minutes
  • The sticky concurrency would timeout
  • If web server 1 were busy, the user would be pushed onto web server 2 loosing the inProc session on web server 1
So, if you are using InProc sessions in a load balanced environment with sticky concurrent sessions and experience random timeouts, there are a couple of things that could be changed.
  • Stop using InProc sessions and use a state server or Sql server to hold sessions in one place
  • Increase the sticky concurrent timeout to a value equal to or above the session timeout

Cheers

Rich
with 4 Comments

Possible nunit bug. Tests in separate assemblies and culture

Embarking on a new project I decided that it would be a much better idea this time to separate the nunit test cases into separate projects from the production assemblies. I had read the recent article in VSJ magazine and was ready put into practice those things that I wasn't routinely doing (I.e. separating my test cases from my production class libraries.

So, the first thing that I wanted to do was write some quick scratch code in order to make sure that everything would work. My scratch code doesn't always tend to be quick as I want to make sure that it works under as many scenarios as possible. Firstly, I made a class library called CompanyName.ExampleProject.dll, wrote a class in the class library, and of course a couple of methods in the class to be able to test. Let's say then we had:

CompanyName.ExampleProject.MyClass that contained:

public string SayHello() method.

All fine so far. Then, being that I like to make sure that everything is set up in the normal fashion, i altered the AssemblyInfo file, adding in all the usual bits like AssemblyTitle, AssemblyCopyright and AssemblyCulture.

Great, I'm all set-up. Now to try and write another project to test it.

So, I set-up another project called CompanyName.TestExampleProject.dll. In a class in this library, I added an nunit test to test the CompanyName.ExampleProject.MyClass class. All looked fine, very little code to test. Run the test.

CompanyName.TestExampleProject.Tests.TestMyClass : System.IO.FileNotFoundException : File or assembly name CompanyName.ExampleProject, or one of its dependencies, was not found.

How odd. Everything compiled correctly and i could even instantiate the SayHello() method from a separate web project, so there was certainly nothing missing.

I verified that everything was in the proper place and that the code was as simple as possible. However, the only thing that I needed to do to make the test pass was to remove any reference to MyClass.

Even if I simply made a fake test and added a line: MyClass c1 = new MyClass then nunit would return the same error message.

Ok, so what would happen if I added the test into the same assembly as the MyClass class? Yep, just as in other projects, now everything would pass. So i could now make my test pass or fail,simply by moving it into another assembly. This shouldn't happen.

Looked at the more specific error message generated by nunit.

at System.Reflection.RuntimeConstructorInfo.InternalInvoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture, Boolean isBinderDefault)

at System.Reflection.RuntimeConstructorInfo.Invoke(BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)

at NUnit.Core.Reflect.Construct(Type type) at NUnit.Core.TestFixture.DoSetUp(TestResult suiteResult)

After more testing, i found the answer. i had added an AssemblyCulture to the main project assembly. Yes, this is a good thing to do. The culture I had added was perfectly legal (en-GB). With the test in the test project (CompanyName.TestExampleProject.dll), if I changed the AssemblyCulture in the other assembly (CompanyName.ExampleProject.dll) to something illegal (E.g. hello) then nunit would tell me straight away that the culture info is not valid. That's good. However, if I changed it to a legal culture, then nunit would not complain until I tried to run the tests.

conclusion
It's my conclusion that this is a bug in nunit. In order to separate my nunit tests into a separate project I need to remove the AssemblyCulture information from the assembly that is being tested. Hardly ideal, but worth it to be able to separate the tests from the production code.

Cheers

R
with 4 Comments

No event handlers when linking from another virtual directory : solution

Strange. The problem is now fixed. To recap, I was basically getting loss of event handlers on an ASP.NET page when I was accessing the page via a link on another page in a seperate virtual directory. Link to the problem is: http://www.dotnetjunkies.com/WebLog/richardslade/archive/2005/08/24/132134.aspx. As this was our development server, I was able to look at the IIS Configuration. On the properties of the Project 2 virtual directory, this was using anonymous access. Integrated Windows Authentication was off. Checking this option made all the event handlers work. Turning it off again seemed to disable any button events. This could be consistantly replicated.
with 3 Comments

No event handlers when linking from another virtual directory

Have a bit of a problem. I'm sure that I will get it solved, but it is proving to be rather tricky. Perhaps there is something obvious that I have missed. After all, my bleary eyes were tired and crumpled from the days coding. Here is what is happening, what we have in place and how I replicate my strange situation.
 
We have 2 development web servers, load balanced with sticky concurrent sessions.
We have many web projects in one solution, but in this example problem I only need 2 projects.
Each project is published to both web servers
The web servers are both set up in the same way
Each of the two projects sits under a separate virtual directory (E.g. www.mysite.com/Project1  and www.mysite.com/Project1/Project2)
Project 1 uses NT Authentication and so does not allow anonymous access
Project 2 allows anonymous access

The problem
From www.mysite.com/Project1 there are a set of links. One of these links takes the users to www.mysite.com/Project1/Project2 . On the project 2 section, there are some buttons with normal .net event handlers behind them. If I navigate directly to www.mysite.com/Project1/Project2 then all works fine. However, if I navigate to www.mysite.com/Project1 , click on the link to project 2, then all of the buttons on project 2 have lost the event handlers. The buttons do nothing more than reload the page. Even more strangely, after I see that project 2 is not working, if I copy the url, close the browser and re-open it, pasting in the url that was not working (project2) then all works fine.
 
So, in the morning, I guess I'm just going to run a whole series of tests, and will hopefully be able to post how this was solved, and probably the silly thing that I haven't yet thought of. However, if someone else has ever seen anything like this, please feel free to share the love and let me know what on earth it could be. Solution to follow (one hopes)....

with 1 Comments