# Unable to create or save session after app runs 24 hours

**URL:** <https://www.ruby-forum.com/t/unable-to-create-or-save-session-after-app-runs-24-hours/142232>\
**Category:** Rails\
**Created:** [July 4, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/unable-to-create-or-save-session-after-app-runs-24-hours/142232 "2008-07-04T21:42:32Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [July 4, 2008, 9:42pm UTC](https://www.ruby-forum.com/t/unable-to-create-or-save-session-after-app-runs-24-hours/142232/1 "2008-07-04T21:42:32Z")

</div>

Hi there,

I know there is a lot of threads on here about sessions, but I could not  
seem to find anyone experiencing this same issue, so alas I made a new  
thread 🙂

Ultimately I am stumped. I am by no means a rails expert, but have done  
quite a few apps now and have yet to have any major issues w/ sessions.  
I am using rails 2.0.2 on this particular project, and I am using the  
active record session store.

I have in my application.rb:

session :session\_expires =\> Time.now + 1.day

and then I have a before\_filter in application.rb, that checks to make  
sure the user has visited the terms and conditions page, before allowing  
them to visit any other page in the application.

so for the first 24 hours after starting the application (running  
lighttpd 1.4.19 w/ fastcgi), things work beautifully, for all users.

then after 24 hours passes, all of the sudden, the system appears that  
it is unable to save any more sessions, and it happens for anyone on the  
site.

so even if i visit the site with a different ip, and absolutely no  
cookies present, i am unable to get it to save a new session, and the  
application is effectively broken. this particular project has a terms  
and conditions page that the user must agree to before entering the  
site. the application realizes that the session is new, so it forces  
them to visit this page, but it gets stuck in a never-ending-loop,  
because since the session is not saved at all, upon the next page load,  
it just goes back to the terms and conditions page. no cookie is set in  
the browser, so that rails can identify the session.

anyone else had an experience like this, where rails is unable to save  
the session and/or set the session cookie, after 24 hours of running  
things in production?

Any help would be super appreciated… Let me know if there is any  
crucial pieces of information that I forgot to include. Happy 4th of  
July if you happen to be in the usa today 🙂

---

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [July 4, 2008, 9:53pm UTC](https://www.ruby-forum.com/t/unable-to-create-or-save-session-after-app-runs-24-hours/142232/2 "2008-07-04T21:53:32Z")

</div>

On Jul 4, 8:42 pm, Scott R. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> lighttpd 1.4.19 w/ fastcgi), things work beautifully, for all users.

You need to think about when this code executes. application.rb is  
loaded precisely once by the fastcgi listener and so that line is  
evaluated exactly once, ie :session\_expires is not being set to when a  
request arrives + 1 day, but to when the server was started + 1 day.

Fred

---

<div class="post-metadata">

**Author:** ![scottrutherford](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d07c76/32.png) [@scottrutherford](https://www.ruby-forum.com/u/scottrutherford)\
**Post date:** [July 4, 2008, 10:20pm UTC](https://www.ruby-forum.com/t/unable-to-create-or-save-session-after-app-runs-24-hours/142232/3 "2008-07-04T22:20:21Z")

</div>

Frederick C. wrote:

> ie :session\_expires is not being set to when a  
> request arrives + 1 day, but to when the server was started + 1 day.

“aha”! Thank you very much. That makes perfect sense. After  
researching this a bit with the new info, I think I may give sliding  
sessions a try as that seems to make sense for my application.

Have a great day.
