The other day I was building a quick demo of an application which used client variables for session management. On logout I was just doing StructClear(client) to clear the client scope. It has been awhile since I have worked on login code for a application which uses client variables for session management, but this is an approach you see used quite often for clearing variables in the session scope on logout.
Well, after logging out using this method I started to see the following error in the ColdFusion logs:
Some quick googling led me to comments in the ColdFusion Livedocs which in turn pointed me in the right direction. StructClear was actually deleting the "read-only" Client variables (CFID, CFToken, URLToken, HitCount, TimeCreated, and LastVisit) and this was causing the error. According to the Livedoc comments it is really only the HitCount variable which causes the issue, but the ColdFusion documentation does say:
ColdFusion lets you delete or change the values of the built-in client variables. As a general rule, avoid doing so.
Given this I updated my logout code to use the ColdFusion ClientVariable functions and all was well:
<cfloop list="#GetClientVariablesList()#" index="var">
<cfset DeleteClientVariable(var) />
I'm pretty sure I knew this at one point, but like I said it has been so long since I've done anything like this with the client scope I had totally forgotten about those ClientVariable functions.