Getting extra sessions created? App losing track of which session it is? Getting "Backtracked Too Far" errors with no apparent cause? Your first stop should be to take a close look at the requests that the application is receiving.

Add this to your Application.java and take a close look at the requests that come in and when.

public WOResponse dispatchRequest(WORequest request) {
    boolean isActionRequest = request.uri().indexOf("/wo/") > -1 || request.uri().indexOf("/wa/") > -1 || request.uri().indexOf("/ajax/") > -1;
    isActionRequest = false;  // Comment this out to enable debug logging
    if (isActionRequest) {
        NSLog.out.appendln("---- start of RR loop ----\n");
        if (request.uri().indexOf("/wo/") > -1) log.info("Received component action request " + request.uri());
        else if (request.uri().indexOf("/wa/") > -1) log.info("Received direct action request " + request.uri());
        else if (request.uri().indexOf("/ajax/") > -1) log.info("Received ajax action request " + request.uri());
        NSLog.out.appendln("request headers " + request.headers());

        WOResponse response =  super.dispatchRequest(request);

        NSLog.out.appendln("returned response " + response.contentString());
        NSLog.out.appendln("returned response headers " + response.headers());
        NSLog.out.appendln("\n");

        return response;
    }
    return super.dispatchRequest(request);
}

Still getting session creation that you can't figure out? Try adding this to Session.java:

public Session() {
    super();
    NSLog.out.appendln(new RuntimeException("Created session " + sessionID());
}

One other thing to look for is accessing a session from a component that isn't properly registered to a session. Calling session() on a component will always return a Session object. If a session doesn't exist, a new one will lazily be created. There are cases where you might think a session should be related to your component, and yet one is not. Calling session() will lazily create a new session, even when you don't want one – which may not be correctly tracked by your Application. This will cause your application to hang when attempting to do a graceful shutdown. Take a look at the method Component.hasSession(). Check to see that you have Session before assuming you really do. This will help keep this runaway sessions in check.

Similarly, WOContext objects also lazily create new sessions. Check Context.hasSession() prior to accidentally creating new sessions.

  • No labels