I've spent a couple of days trying to track down an issue with a sidekiq job that completes successfully but database writes that should have occurred in the job are not happening.
We started noticing this shortly after upgrading to version 1.5.1 and think we've tracked the problem down to a change of behaviour that was introduced in that update.
The model contains multiple JSON columns that use typed_store and we are running a couple of jobs that would update different columns. Examining the queries that are run when one of the JSON columns is updated we can see that all other empty JSON columns are also updated to nil even though they are not part of the query.
I put together a simple example using this class:
class TypedExample < ApplicationRecord
typed_store :pet_metadata, coder: ActiveRecord::TypedStore::IdentityCoder do |p|
p.string :pet_name
p.string :pet_type
p.integer :pet_age
end
typed_store :car_metadata, coder: ActiveRecord::TypedStore::IdentityCoder do |p|
p.string :car_make
p.integer :car_year
end
typed_store :house_metadata, coder: ActiveRecord::TypedStore::IdentityCoder do |p|
p.string :house_address
p.integer :house_price
end
end
We believe that this has introduced a race condition where another job has updated a different JSON column but this has also updated other JSON columns to nil.
Can you give any background on why updating one JSON column should have any effect on other columns? It seems like dangerous behaviour.
In the meantime we are rolling back to 1.5.0 and putting in other mitigations to try to avoid similar race conditions.
I've spent a couple of days trying to track down an issue with a sidekiq job that completes successfully but database writes that should have occurred in the job are not happening.
We started noticing this shortly after upgrading to version 1.5.1 and think we've tracked the problem down to a change of behaviour that was introduced in that update.
The model contains multiple JSON columns that use
typed_store
and we are running a couple of jobs that would update different columns. Examining the queries that are run when one of the JSON columns is updated we can see that all other empty JSON columns are also updated tonil
even though they are not part of the query.I put together a simple example using this class:
and this example record:
See this example updating fields of the
house_metadata
column:Clearly all JSON columns are updated even though the query only targeted
house_metadata
.In 1.5.0, only columns that already had a value were updated so side effects would be less widespread.
We believe that this has introduced a race condition where another job has updated a different JSON column but this has also updated other JSON columns to
nil
.Can you give any background on why updating one JSON column should have any effect on other columns? It seems like dangerous behaviour.
In the meantime we are rolling back to 1.5.0 and putting in other mitigations to try to avoid similar race conditions.