On Oct 22, 2008, at 1:34 PM, Simon McLean wrote:
Blimey, this has taken me weeks to figure out...
We've been plagued with zombie sessions for weeks on a couple of production apps. One, for example, is used by a team of 5 people who sign on in the morning and out in the evening, by which time the app is busy running 300+ sessions!
Anyway, after much digging I finally nailed it down to a component that was being used to render email. We use the following method to instantiate a component and then call generateResponse().contentString() to get it's html content:
public static WOComponent instantiatePage(String pageName) {
// Create a context from a fake request
WORequest request = new WORequest("GET", "", "HTTP/1.1", null, null, null);
WOContext context = WOApplication.application().createContextForRequest(request);
return WOApplication.application().pageWithName(pageName, context);
}
The problem was that one of the components used as an email touched the session. I believe because we are using a fake context this results in a new session being created. I'm not sure why those extra sessions don't just expire like normal ones ? But anyway, problem solved. I can sleep again.
Simon
I find this interesting for multiple reasons :-) I have experienced the zombie sessions myself, and now that you mention it... It was in an app that did exactly this... Also, I've recently filed a patch to Wonder's ERJavaMail that does something similar to this. So I think I've unwittingly fixed more than one bug for myself! Hooray! \(^_^)/ Wonder 167.
/**
* A convenience method to generate a page's response content without
* caching it in the backtrack cache, attempting to set cookies, or
* stomping on the current context.
* @param component - the page component used to generate the response.
* @return a response object containing the generated content
*/
public static WOResponse generateResponseWithoutCaching(WOComponent component) {
WOContext context = (WOContext)component.context().clone();
WOResponse response = WOApplication.application().createResponseInContext(context);
context.deleteAllElementIDComponents();
if(!component.equals(context._pageElement())) {
context._setPageChanged(true);
context._setPageElement(component);
context._setCurrentComponent(component);
}
component.appendToResponse(response, context);
return response;
}
I don't think it's the context so much as what is happening in generateResponse _after_ appendToResponse is called though. I say that because I'm obviously using a cloned context, but no new session is created... I just tested it, and my session constructor is only logging one session created from launch to mail sent.... I'm certain the pages are touching the session when generating their content because they are mailed using whatever language is set in the session's current localization. So unless the bug is borking _that_ session, it shouldn't be an issue once patched. I'm curious... did you witness/log a new session being created as the result of the mailings?