Repository navigation
Better double checked locking in load_schema - #37288
Conversation
|
@casperisfine do you know what change broke this or has it always been broken? |
|
@eileencodes I'll do some git spelunking to try to figure that out, however we're seeing these errors since a fairly long time, but they are very infrequent, so it took a while to pinpoint. |
|
Ok, so purely based on the source, I'd say the issue was introduced in 6a5a814 |
4387aa0 to
3bf1617
Compare
|
I just pushed a test that reproduce the error on master. However it seems like my fix is totally breaking the test suite with a StackLevelTooDeep. I'll try to figure that out. |
4730cd6 to
f0fc5cb
Compare
|
Ok, so the So the next best thing is to reset the cc @matthewd since you seem to have worked in this area previously. |
f0fc5cb to
f7d4f67
Compare
Better double checked locking in load_schema
So we've witnessed some weird issues in production. Some
serializedattributes ended up not being deserialized from time to time.After investigating a bit, it end up being the fallout of the following exception:
What happened here is that a call to
connection.lookup_cast_type_from_columnraises and error, which leave the model with@columns_hashset, but not all attribute methods etc defined and@schema_loaded = false.So effectively the model is only half-way initialized, but further calls to
load_schemabail out early because@columns_hashis set.Fix
So this is a very straightforward change, we just make sure that the condition used for bailing out early is one that prove everything was properly initialized.
This is not perfect though, because the model still end up in an inconsistent state, however it will recover on the next
load_schemacall. What we could do would be to add arescueblock to unset@column_hashand others. Let me know what you think about this.Testing
I'd like to add a regression test for this, but to reproduce the error I think I need some stubbing helper, and I'm having a hard time to understand the ones available in Rails test suite.
@etiennebarrie @deuxpi @rafaelfranca @Edouard-chin @eileencodes @seejohnrun