• Dylan Griffith's avatar
    Detect and log cross-database modifications in production · 5d0ced2f
    Dylan Griffith authored
    This adds a Rack middleware and Sidekiq middleware for detecting
    "Cross-database modification" violations. These occur when you query 2
    different databases in the context of a single transaction. Previously
    we only wrapped our RSpec code with this detection logic but we found
    that it was often causing lots of false positives in RSpec (in test-only
    code) which made it hard to sort through the real issues. In addition we
    want extra validation by running this in production and therefore
    detecting code that our specs may be missing.
    
    The middlewares use a feature flag `detect_cross_database_modification`
    which we intend to enable for a small percentage of time.
    
    The middlewares can also be disabled by setting the env var
    `DISABLE_CROSS_DATABASE_MODIFICATION_DETECTION=true` and restarting the
    application. This environment variable is an extra safety net if the
    middlewares are causing problems.
    5d0ced2f
database.rb 11.1 KB