Copy link to clipboard
Copied
I've been working on this for a month and I'm stumped.
This is the code to logout...
<cfscript>
StructClear(session);
StructClear(application);
</cfscript>
...that's it (besides some HTML "You've logged out").
This works fine on our DEV & TEST environments, but gets a 500 Error on our PROD environment. Nothing in the error log. I've searched exhaustively and cannot find anything. And we have a System Admin who is difficult..."it's the code."
Any idea?
Thanks in advance.
ColdFusion v11.
Finally figured this out...just one of those weird non-logical flukes.
Basically, it was a corrupt directory. We noticed that we would get 500 errors on even basic HTML pages. Deleting and re-creating the directory didn't work. So we changed the directory name from "logout" to "logout2" and voila...that worked!
Hope this might help others down the road.
Thanks for everyone's assistance with this!
Copy link to clipboard
Copied
If you clear the application structure on logout, it will kill app scoped variables for everyone, not just the current user. Probably not what you intended.
Perhaps wrap with try/catch and see if the 500 still occurs.
-Nic
Copy link to clipboard
Copied
Thanks for your explaining the clearing of the application structure, Nic. Unfortunately I am in one of these controlled PROD environments and it will take a minimum of 4 weeks to do a release to PROD.
I have tried isolating the StructClear as such...
<cfif IsDefined("url.clear")>
<cfset strCleared = 'None'>
<cfif url.clear EQ 'session'>
<cfscript>
StructClear(session);
</cfscript>
<cfset strCleared = 'Session'>
<cfelseif url.clear EQ 'application'>
<cfscript>
StructClear(application);
</cfscript>
<cfset strCleared = 'Application'>
</cfif>
<cfoutput>#EncodeForHTML(strCleared)#</cfoutput> has been cleared.
<cfabort>
</cfif>
...and running each of these...
...and still getting a 500 error for each. Again, happens only on PROD. Works fine on DEV & TEST.
I'm guessing it's either a server (IIS or CF Admin) setting that is causing this error (as the logout.cfm and application.cfm codes are the same on each environment), but unable to replicate this error on DEV or TEST.
Any other ideas?
Copy link to clipboard
Copied
I remember a number of years ago it was documented to not call structClear(session). That may have changed since CF9 or whenever that was. What are you trying to accomplish? I'd imagine ending the session in Application.cfc might be more what you are looking for. In your onRequestStart you could look for a URL param or template path, and then just call onSessionEnd().
-Nic
Copy link to clipboard
Copied
I'm just trying to do a basic logout...which can be accomplished using a structClear(session). The other structClear(application) was left over from the previous developer...not exactly sure what his reasoning was and I have reservations on removing it (fearing it might impact the app somewhere else).
Thank you for your suggestion on ending the session in the Application.cfm file. But I'm concerned that if structClear(session) does not work on PROD (but works on DEV & TEST), then I might have the same problem when implementing your suggestion. That is, I'm wondering if a setting is not letting me clear/end the session properly on PROD.
Copy link to clipboard
Copied
I think it's a terrible idea to clear the application scope whenever a user logs out. This is just asking for trouble. You might want to investigate why that was put into place so you can get rid of it. I'm not at all surprised that you're getting 500 errors when you do that repeatedly in a production environment.
Nic may also be right about it being a bad idea to just call structClear with the session scope as well, and his suggestion to handle this another way sounds good to me.
Dave Watts, Fig Leaf Software
Copy link to clipboard
Copied
You might also want to take a look at the logs to see what exception was thrown.
I agree with Dave - if you do a structClear(application) it is going to cause exceptions in a production environment -- the reason for this is that the application scope is shared among all users/requests for the application. So if one request clears the application scope, and another request is concurrently executing it will have expected that the application variables are defined, but since they are not (due to the structClear) it will throw an exception.
Given this, it is likely that when you look at the logs it will say the reason for the 500 exception was application.SomeVariableName is undefined.
Copy link to clipboard
Copied
Thank you all for your inputs...I greatly appreciate it!
I did try having a couple of persons logging in simultaneously to our DEV environment and then try logging out...was able to log out with no problem. So not sure if it is the structClear(application) that is causing my problem on PROD (albeit makes sense from your details).
Also if the structClear(application) is the culprit, then I should not be getting a 500 error when running logout.cfm?clear=session which executes only structClear(session)....see code above. Executing the structClear(session) generates the 500 error only on PROD, but not on DEV nor TEST environments.
Will implement your suggestions, but hoping someone might have a simpler flip-the-setting on IIS or CF Admin.
Thanks all!
Copy link to clipboard
Copied
The 500 error means that something is wrong with the webserver, but the webserver cannot be specific about what the error is.
Clearing the application scope, as has already been pointed out, ruins the application scope for everyone, not just the user logging out.
As Nic suggested, place the code in question between CFTRY/CFCATCH tags to see if that will shed light on this issue.
<cftry>
your code
<cfcatch>
<cfmail to="you@yourdomain.com" from="webmaster@yourdomain.com" type="html" subject="error">
<cfdump var="#cfcatch#" />
</cfmail>
There is an error going on; we've been notified. We apologise for any inconvenience.<cfabort />
</cfcatch>
</cftry>
HTH,
^ _ ^
Copy link to clipboard
Copied
Finally figured this out...just one of those weird non-logical flukes.
Basically, it was a corrupt directory. We noticed that we would get 500 errors on even basic HTML pages. Deleting and re-creating the directory didn't work. So we changed the directory name from "logout" to "logout2" and voila...that worked!
Hope this might help others down the road.
Thanks for everyone's assistance with this!