Threading weirdness in method_missing

Can somebody take a look at the discussion here:

(suggested fix at the bottom)

tl;dr: there's an obscure race condition which only happens when two threads dispatch into method_missing on instances of the same ActiveRecord model. The net result is that one of them successfully generates + calls the requested method while the other fails with NoMethodError. :frowning:

The fix is (as far as I can tell) pretty straightforward, so this would be great to get into 4.0.1.

--Matt Jones