PDA

View Full Version : HttpHandler Initialization



dani
10-10-2008, 12:24 PM
Hello,
I have installed a dream server as a HttpHandler in Asp.Net, and looking at the log messages it seems that the class HttpHandler is created 2 times and each time the IDreamEnvironment is also created.
I think that the problem is in SyncRoot and _env, which are defined as

private object SyncRoot = new object(); (httphandler.cs, line 48)
private IDreamEnvironment _env;

and maybe should be

private static object SyncRoot = new object();
private static IDreamEnvironment _env;

Is that correct?

SteveB
10-20-2008, 11:08 PM
That's odd that it is being created twice. Do you know why that might happen?

dani
10-21-2008, 12:27 PM
I think that ASP.NET receives in a short time 2 petitions to the httphandler and it has to create 2 MindTouch.Dream.Http.HttpHandler classes because the first petition needs a longer time to proceed.
Then the synchronization code in the constructor does not work because the SyncRoot object is not static, and each object constructs its IDreamEnvironment _env, each one with all his initialitzations.
If you change the code making SyncRoot static the problem of the first call disappears, but when ASP.NET needs to process 2 concurrent petitions it constructs another httphandler (I think it uses a pool of handler classes) and creates another environtment.
I think the solution is to define both SyncRoot and _env static, but I'm not sure if this is correct for all the situations.

SteveB
10-30-2008, 01:16 AM
Hmm, I wonder what is the recommended fix here. I mean what if we did want two handlers, because there are multiple entry points at once. At least, that's supported by mindtouch.dream.host.exe. I don't know if IIS would support it as well.

SteveB
12-19-2008, 07:21 PM
I fix for this issue was checked in today: http://bugs.developer.mindtouch.com/view.php?id=5520