Integrate request_store to help with Threading issues#340
Integrate request_store to help with Threading issues#340binarylogic merged 1 commit intobinarylogic:masterfrom
Conversation
|
👍 👍 👍 that was fast, thanks @steveklabnik!! |
|
I like this, want to look at it more. Not a big fan of creating a new dependency, but not sure I have a choice here. |
|
Sure thing. One good thing about the gem is that if you're already using |
|
This seems important. Is anyone already using Authlogic with Puma or another thread web-server? Have changes in Puma or Ruby 2 or 2.1 made this unnecessary? |
|
I'm on board, if someone wants to solve the merge confllcits I'll pull in. Otherwise I'll have to do it this weekend some time. |
|
I've noticed that Rails itself uses Thread.current, so I wonder if this is still necessary? |
|
@nathany yeah, Thread.current is the problem itself. Authlogic sets the controller variable, but doesn't unset it after the request. I ran into an issue on a non-threaded server where |
|
I can solve the merge conflicts soon if this patch is wanted. And yes, @tiegz, exactly. |
|
Thanks @tiegz and @steveklabnik |
|
I've updated the PR to fix the merge conflicts. |
|
sweet thanks |
Integrate request_store to help with Threading issues
|
😍 👍 🎊 |
Hey there! I ran into issues using
Thread.currentwhile working with Draper, and apparently Authlogic has them too. So I wrote a gem to handle it, and I figured you may want to use it too. Here's the Draper discussion: drapergem/draper#390Fixes #335.
The Issue
If you use
Thread.currentto store state, and you use one of those fancy threaded servers like Puma or Thin, then what's inThread.currentdoesn't get cleared per-request like it would if you were using Webrick or whatever. This causes subtle bugs.The Fix
Basically, I wrote a gem that gives you 'request local' storage. It quacks like a
Hash, just likeThread.current, but a middleware ensures that you get a clean slate every request.I ran your tests on 1.9.3 and they were passing, but the gem works with basically every modern Ruby ever (and some not-so-modern ones), so no issues there.
Thanks! ❤️ ❤️ ❤️