Posted by Ben Jackson
Fri, 29 Aug 2008 03:42:17 GMT
Just figured out the answer to a problem which was driving me nuts. Consider the following code. Can you see what's wrong?
def register
if logged_in?
self.current_user.forget_me
cookies.delete :auth_token
reset_session
end
end
Neither could I. Even when the ActionController::InvalidAuthenticityToken exception notifications started flooding in.
Looking through the Rails docs and the mailing lists for the exception revealed little. I was setting my secret key for protect_from_forgery, and all of my forms used form_for which already sets the authentication token in the form.
It turns out that I had committed a simple, fatal error: resetting the session without redirecting.
When you reset the session, the session key changes. Redirecting after this will clear the user's session token, and a new one will be generated for the new session.
If you do what I did, however, the session gets reset, but the token will not. The next time your user submits any form (or POST link) your app will go batshit.
So the lesson: ALWAYS REDIRECT AFTER RESETTING THE SESSION. You'll be happier for it.
Posted by Ben Jackson
Thu, 07 Aug 2008 18:14:00 GMT
Hardware is complicated.
Hard drives corrupt. Power units short out. Pixels die. Time marches on.
But every now and then, a mystery comes along which makes one question whether or not the electrons shooting around underneath the shiny brushed aluminum have some sort of sinister, vengeful will of their own.
Case in point: one iMac G5 PPC. The machine in question is a bit more than two years old and is under Applecare. Over the last 4-5 months, it has begun to go into hibernation mode whenever the CPU is taxed above a certain level.
We took it to the helpful folks over at the Macstore Ipanema. After a matter of days, we received the machine back with a report that the techs were unable to reproduce the problem in the lab.
After some electrical problems with our Mac Pro, we did a complete restoration of the electrical infrastructure of the house. The Mac Pro which was shorting out its surge protector returned to its normal, functioning state, but the problems with the iMac continued.
Confused, we brought the machine back to the Macstore, which was again unable to reproduce the issue but proceeded to change the logic board and power management unit to eliminate them as potential problems.
The machine returned and almost immediately began acting up again.
At this point we sent the machine back to the techs and immediately called Apple in the US, who directed us to Applecare Brazil. We opened a case with them to replace the machine, and were informed after 4 days that the machine could not be replaced as the techs could not reproduce the issue and therefore could not determine which part was at fault.
Determined, we took the machine to another shop to have it looked at: Mac Business Experts in Copacabana. After 4 days of testing they reported that they, too, were unable to reproduce the problem. The only fault they found was a broken wire in the cooling system, which they seem to think is not a likely cause. After it was replaced and returned today, the machine has already died. We're still waiting on the replacement part.
We have tried plugging the machine into other wall sockets, and the other Macs are all running fine. We are pretty damn sure that the problem is not in our electricity.
If anyone reads this and can suggest what else might possibly be wrong, we will be very, very appreciative. Feel free to leave any ideas in the comments.
Update: We've uploaded a video of the machine crashing to YouTube for the record.
Second update (Aug. 28): We are still waiting on the cooling wire to arrive at Mac Business Experts. My blood is beginning to boil. The Mac can now no longer sustain running even just the HP scanner's software (with nothing else open) without going into hibernation.
But in what is perhaps a sign of desperation given Google's growing market share dominance, ninemsn is running a new Live Search promotion - Secret Search - offering surfers the chance to win prizes including the iPod Nano, Shuffle and Touch just for conducting searches. … Ninemsn's head of Live Search, Alex Parsons, said if the Zune music player was sold in Australia it would have been offered as a prize instead. "Where we don't have a great product or we don't have a product at all there's no internal edict that says we're not allowed to use competitor products," he said.
Could set off a trend in the other companies if it goes well (which it should).