Session is Invalid Bug (and Fix)

Last night I ran across a bug I had not seen before. I was hitting a dev site using sessions and I got a "Session is Invalid" error. A quick google search found this post over at bpurcell.org. This led to a Tech Note that describes how to fix the issue.

Archived Comments

Comment 1 by BertD posted on 3/12/2004 at 9:06 PM

maybe you should tell Mr Forta - I hit this bug when using FeedDemon to view his blog
:)
Cheers
Bert

Comment 2 by Sami Hoda posted on 9/27/2005 at 12:13 AM

I am getting this error on a installation of CF7. Anyone know if it survived to CF7?

Sami

Comment 3 by Eric posted on 5/19/2008 at 8:16 PM

I'm getting this error in CF7. Does anyone know if the fix is still applicable to ie7? Or is it something different.

Comment 4 by Erik C posted on 8/27/2008 at 11:47 PM

I still get this error on CF 8.01.

Comment 5 by dan posted on 10/2/2008 at 12:14 AM
Comment 6 by Tim posted on 10/20/2008 at 11:10 PM

@Dan -- what does that post say -- Id rather not join yet another group to see the post.

Comment 7 by Scott Fitchet posted on 9/22/2009 at 6:05 PM

Saw this error for the first time today (version 7 service). I was able to get past the error by temporarily changing my sessiontimeout to 0. After the next request I then switched back to the default timeout setting with no problems (yet).

Comment 8 by ColdFusion development posted on 1/4/2010 at 3:10 PM

Scott, you can simply clear your cookies and that will have the same effect as you'll be given a new CFID etc.

Comment 9 by ColdFusion development posted on 1/4/2010 at 3:17 PM

Just added this to the OnError section of my application.cfc and it will clear cookies automatically.

<cfif isDefined("except.message")>
<cfif except.message is "Session is invalid">
<cfcontent reset="yes">
<cfset tx = structclear(cookie)>
<h3>Your session has timed out <cfoutput>#now()#</cfoutput>. <a href="/">Click here or wait 1 second</a></h3>
<script type="text/javascript">
window.setTimeout(redir, 2000);
function redir()
{
window.location = '/?cb=<cfoutput>#getTickCount()#</cfoutput>';
}
</script>
<cfabort>
</cfif>
</cfif>

Comment 10 by thangapandyan posted on 6/17/2010 at 11:19 AM

I have an error "session is invalid "while running the website ,
i haven't use any application.cfc file in my application ,but i using application.cfm file many places in my application.can u suggest me,where i can place the following code to avoid
session error in application,

<cfif isDefined("except.message")>
<cfif except.message is "Session is invalid">
<cfcontent reset="yes">
<cfset tx = structclear(cookie)>
<h3>Your session has timed out <cfoutput>#now()#</cfoutput>. <a href="/">Click here or wait 1 second</a></h3>
<script type="text/javascript">
window.setTimeout(redir, 2000);
function redir()
{
window.location = '/?cb=<cfoutput>#getTickCount()#</cfoutput>';
}
</script>
<cfabort>
</cfif>
</cfif>

Comment 11 by thangapandyan posted on 6/17/2010 at 11:21 AM

I have an error "session is invalid "while running the website ,
i haven't use any application.cfc file in my application ,but i using application.cfm file many places in my application.can u suggest me,where i can place the following code to avoid
session error in application,

<cfif isDefined("except.message")>
<cfif except.message is "Session is invalid">
<cfcontent reset="yes">
<cfset tx = structclear(cookie)>
<h3>Your session has timed out <cfoutput>#now()#</cfoutput>. <a href="/">Click here or wait 1 second</a></h3>
<script type="text/javascript">
window.setTimeout(redir, 2000);
function redir()
{
window.location = '/?cb=<cfoutput>#getTickCount()#</cfoutput>';
}
</script>
<cfabort>
</cfif>
</cfif>

Comment 12 by Seun Ojo posted on 6/21/2010 at 2:21 PM

Hi,

Nice one on for your suggestion; the following worked for me:

<cfif isDefined("exception.message")>
<cfif exception.message is "Session is invalid">
<cfcontent reset="yes">
<cfset tx = structclear(cookie)>
<script type="text/javascript">
window.setTimeout(redir, 100);
function redir()
{
window.location = '/app_root_folder?reset=<cfoutput>#getTickCount()#</cfoutput>';
}
</script>
<cfabort>
</cfif>
</cfif>

Also, note the use of "exception" as against the "except" in the earlier post.

Thanks everyone.