mirror of
https://github.com/gnustep/libs-gsweb.git
synced 2025-04-22 15:00:45 +00:00
* fixed session (re)creation bug
* code cleanups git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/gsweb/trunk@26625 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a8542deae4
commit
dc1fbc6547
5 changed files with 75 additions and 118 deletions
|
@ -1,3 +1,11 @@
|
|||
2008-04-20 David Wetzel <dave@turbocat.de>
|
||||
GSWeb.framework/GSWApplication.m
|
||||
GSWeb.framework/GSWComponentRequestHandler.m
|
||||
GSWeb.framework/GSWServerSessionStore.m
|
||||
GSWeb.framework/GSWSessionStore.m
|
||||
* fixed session (re)creation bug
|
||||
* code cleanups
|
||||
|
||||
2008-05-25 Sebastian Reitenbach <sebastia@l00-bugdead-prods.de>
|
||||
|
||||
* GSWeb.framework/stacktrace.m (PLATFORM_UNIX): Define
|
||||
|
|
|
@ -1755,10 +1755,9 @@ to another instance **/
|
|||
inContext:(GSWContext*)aContext
|
||||
{
|
||||
GSWSession* session=nil;
|
||||
GSWRequest* request=nil;
|
||||
|
||||
session = [_sessionStore checkOutSessionWithID:sessionID
|
||||
request:request];
|
||||
request:[aContext request]];
|
||||
|
||||
if (session != nil)
|
||||
{
|
||||
|
@ -1848,11 +1847,12 @@ to another instance **/
|
|||
GSWSession* session=nil;
|
||||
|
||||
session=[self _createSessionForRequest:aRequest];
|
||||
NSDebugMLLog(@"sessions",@"session:%@",session);
|
||||
|
||||
// is this done in 4.5? -- dw
|
||||
[_statisticsStore _applicationCreatedSession:session];
|
||||
|
||||
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
-(GSWSession*)_createSessionForRequest:(GSWRequest*)aRequest
|
||||
|
@ -1861,37 +1861,19 @@ to another instance **/
|
|||
Class sessionClass=Nil;
|
||||
GSWSession* session=nil;
|
||||
|
||||
[self lock];
|
||||
NS_DURING
|
||||
{
|
||||
sessionClass=[self _sessionClass];
|
||||
NSDebugMLLog(@"sessions",@"sessionClass:%@",sessionClass);
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,
|
||||
@"In _sessionClass");
|
||||
LOGException(@"%@ (%@)",localException,[localException reason]);
|
||||
//TODO
|
||||
[self unlock];
|
||||
[localException raise];
|
||||
};
|
||||
NS_ENDHANDLER;
|
||||
[self unlock];
|
||||
sessionClass=[self _sessionClass];
|
||||
|
||||
if (!sessionClass)
|
||||
{
|
||||
//TODO erreur
|
||||
NSDebugMLLog0(@"application",@"No Session Class");
|
||||
NSAssert(NO,@"Can't find session class");
|
||||
}
|
||||
{
|
||||
NSAssert(NO,@"Can't find session class");
|
||||
}
|
||||
else
|
||||
{
|
||||
session=[[sessionClass new]autorelease];
|
||||
};
|
||||
NSDebugMLLog(@"sessions",@"session:%@",session);
|
||||
{
|
||||
session=[[sessionClass new]autorelease];
|
||||
}
|
||||
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
|
|
|
@ -263,19 +263,22 @@ GSWResponse * _dispatchWithPreparedApplication(GSWApplication *app, GSWContext *
|
|||
{
|
||||
GSWSession * session = nil;
|
||||
GSWResponse * response = nil;
|
||||
GSWRequest * request = [aContext request];
|
||||
NSString * sessionID;
|
||||
|
||||
sessionID = [requestHandlerDict objectForKey:GSWKey_SessionID[GSWebNamingConv]]; //@"wosid"
|
||||
if ((!sessionID)) {
|
||||
session = [app _initializeSessionInContext:aContext];
|
||||
if (session == nil) {
|
||||
response = [app handleSessionCreationErrorInContext:aContext];
|
||||
}
|
||||
} else {
|
||||
session = [app restoreSessionWithID:sessionID inContext:aContext];
|
||||
if (session == nil) {
|
||||
response = [app handleSessionRestorationErrorInContext:aContext];
|
||||
}
|
||||
}
|
||||
|
||||
if (session == nil) {
|
||||
response = [app handleSessionCreationErrorInContext:aContext];
|
||||
} else {
|
||||
if (response == nil) {
|
||||
response = _dispatchWithPreparedSession(session, aContext, requestHandlerDict);
|
||||
}
|
||||
|
||||
|
|
|
@ -97,15 +97,10 @@ RCS_ID("$Id$")
|
|||
request:(GSWRequest*)aRequest
|
||||
{
|
||||
GSWSession* session=nil;
|
||||
//OK
|
||||
LOGObjectFnStart();
|
||||
NSDebugMLLog(@"sessions",@"aSessionID=%@",aSessionID);
|
||||
NSDebugMLLog(@"sessions",@"sessions=%@",_sessions);
|
||||
session=[_sessions objectForKey:aSessionID];
|
||||
NSDebugMLLog(@"sessions",@"session=%@",session);
|
||||
LOGObjectFnStop();
|
||||
|
||||
session = [_sessions objectForKey:aSessionID];
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
/** Should be Locked **/
|
||||
|
|
|
@ -101,85 +101,54 @@ RCS_ID("$Id$")
|
|||
request:(GSWRequest*)aRequest
|
||||
{
|
||||
GSWSession* session=nil;
|
||||
BOOL isCheckedOut=YES;
|
||||
int tryCount=0;
|
||||
int startTime=(int)time(NULL);
|
||||
int currentTime=startTime;
|
||||
int expirationTime=60; // default exp time is 60s
|
||||
//OK
|
||||
LOGObjectFnStart();
|
||||
NSDebugMLLog(@"sessions",@"aSessionID=%@",aSessionID);
|
||||
NSDebugMLLog(@"sessions",@"self=%@",self);
|
||||
do
|
||||
|
||||
session = [self restoreSessionWithID:aSessionID
|
||||
request:aRequest];
|
||||
|
||||
if (!session) {
|
||||
return nil;
|
||||
}
|
||||
|
||||
SYNCHRONIZED(_lock) {
|
||||
|
||||
BOOL isCheckedOut = YES;
|
||||
|
||||
GSWSessionTimeOut* entry = [_timeOutManager sessionTimeOutForSessionID:aSessionID];
|
||||
int expirationTime=(int)[entry sessionTimeOutValue];//seconds
|
||||
|
||||
NSLog(@"expirationTime=%d",(int)expirationTime);
|
||||
|
||||
isCheckedOut=[entry isCheckedOut]; // See if session is used
|
||||
|
||||
if (!isCheckedOut)
|
||||
{
|
||||
tryCount++;
|
||||
if ([self tryLock])
|
||||
session = [self restoreSessionWithID:aSessionID
|
||||
request:aRequest];
|
||||
if (session) {
|
||||
NSLog(@"CheckOut: %@. SessionID:%@",aSessionID,[session sessionID]);
|
||||
|
||||
// If sessionID has Changed, re-find entry
|
||||
if (![[session sessionID] isEqualToString:aSessionID])
|
||||
{
|
||||
GSWSessionTimeOut* entry=[_timeOutManager sessionTimeOutForSessionID:aSessionID];
|
||||
NS_DURING
|
||||
{
|
||||
expirationTime=(int)[entry sessionTimeOutValue];//seconds
|
||||
//NSLog(@"expirationTime=%d",(int)expirationTime);
|
||||
isCheckedOut=[entry isCheckedOut]; // See if session is used
|
||||
//NSLog(@"aSessionID=%@ isCheckedOut=%d",aSessionID,(int)isCheckedOut);
|
||||
//NSLog(@"entry=%@",(int)entry);
|
||||
|
||||
// if it is not used, restore it and so on....
|
||||
if (!isCheckedOut)
|
||||
{
|
||||
session=[self restoreSessionWithID:aSessionID
|
||||
request:aRequest];
|
||||
if (session)
|
||||
{
|
||||
//NSLog(@"CheckOut: %@. SessionID:%@",aSessionID,[session sessionID]);
|
||||
|
||||
// If sessionID has Changed, re-find entry
|
||||
if (![[session sessionID] isEqualToString:aSessionID])
|
||||
{
|
||||
aSessionID=[session sessionID];
|
||||
entry=[_timeOutManager sessionTimeOutForSessionID:aSessionID];
|
||||
};
|
||||
isCheckedOut=[entry isCheckedOut];
|
||||
if (!isCheckedOut)
|
||||
{
|
||||
[session _createAutoreleasePool];
|
||||
[entry setIsCheckedOut:YES];
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSDebugMLLog(@"sessions",@"Can't checkOutSessionID=%@",aSessionID);
|
||||
localException=ExceptionByAddingUserInfoObjectFrameInfo0(localException,
|
||||
@"In checkOutSessionWithID:request:");
|
||||
LOGException(@"%@ (%@)",localException,[localException reason]);
|
||||
// Put the previous check in/out state
|
||||
[entry setIsCheckedOut:isCheckedOut];
|
||||
[self unlock];
|
||||
[localException raise];
|
||||
}
|
||||
NS_ENDHANDLER;
|
||||
[self unlock];
|
||||
currentTime=(int)time(NULL);
|
||||
if (isCheckedOut) // Session already check out. Wait...
|
||||
{
|
||||
NSTimeIntervalSleep(0.010); // sleep for 10 ms
|
||||
if (tryCount%100==0)
|
||||
NSLog(@"Try check out %@ for %d seconds (tryCount=%d)",aSessionID,(currentTime-startTime),tryCount);
|
||||
};
|
||||
[NSException raise:@"IllegalStateException"
|
||||
format:@"How can a session ID change? -- dw"];
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
NSLog(@"Try lock failed");
|
||||
currentTime=(int)time(NULL);
|
||||
};
|
||||
isCheckedOut = [entry isCheckedOut];
|
||||
NSLog(@"isCheckedOut: %d", isCheckedOut);
|
||||
|
||||
if (!isCheckedOut)
|
||||
{
|
||||
[session _createAutoreleasePool];
|
||||
[entry setIsCheckedOut:YES];
|
||||
}
|
||||
}
|
||||
}
|
||||
while(isCheckedOut && (currentTime-startTime)<expirationTime);
|
||||
NSDebugMLLog(@"sessions",@"session=%@",session);
|
||||
LOGObjectFnStop();
|
||||
}
|
||||
END_SYNCHRONIZED;
|
||||
|
||||
return session;
|
||||
};
|
||||
}
|
||||
|
||||
//--------------------------------------------------------------------
|
||||
-(void)checkInSessionForContext:(GSWContext*)aContext
|
||||
|
|
Loading…
Reference in a new issue