I have inherited a Rails 3 application with a cookie/session problem. Namely, something seems to be non-deterministically cleaning out all of the information in a session or cookie, every so often. I’ve reproduced the bug while watching in a console, and the application is sending back, every so often, an empty session cookie, clear as day. It’s nicely Base64 encoded as I would expect from a Rails cookie store; seems something is overzealous about deleting a session and/or cookies. Great, a bug, let’s fix it.
My question is: how do I debug a session or cookie problem in Rails 3? This application has a fairly sizable mound of dependencies and a sizable heap of its own code; I’d rather just observe the session and cookies, I don’t know of a good way to see what’s editing them. I can output what they are at the beginning of a request, and after one, but it’s all Very Rails Magical in the middle. I don’t even see how to overwrite the session setters, since it’s just a hash implemented in C. I did some ack’ing but it didn’t reveal anything amazing, and I know a lot of session magic happens in Rails itself so I doubt the actual session = {} is happening in the application.
Any ideas here? What can I monkeypatch, where can I plug in? Is there some test facility for sessions or cookies I’m unaware of?
I’ve done some Rails session and cookie debugging and it was really just a matter of opening up the Rails code and combing through it, putting debug statements in it, etc. It’s hard at first but you learn a lot and it becomes easier the next time. The Rails codebase is actually not bad once you get used to it.
Maybe this hasn’t helped but will hopefully make you feel better if you have to dig in. With my poor luck, the next answer will be someone saying ‘oh yeah, just flip this configuration switch’. Fwiw, in my case Rails was doing nothing incorrect or bizarre with the session.