• Bob Van Landuyt's avatar
    Don't try to enable the request store twice · 48f069ee
    Bob Van Landuyt authored
    When calling `#with_request_store` we enable the request store and
    ensure it's disabled after the block completes.
    
    However, since the request store is thread local, we can't enable and
    disable it twice withing the same block. In regular circumstances,
    this doesn't happen, since we only enable the request store in
    middleware, and they both run in a different process:
    
    - Using RequestStore::Middleware as a rack middleware for requests
    - Using Gitlab::SidekiqMiddleware::RequestStoreMiddleware for
      sidekiq-server.
    
    In specs this could happen when running Sidekiq::Testing.inline!. If
    that was used within a spec that had the `:request_store` tag, or
    within a feature/request spec that ran the rack middleware.
    
    In this case, the Sidekiq middleware would disable and clear the
    request store too soon, causing failures in the specs that counted on
    the request store, for example specs counting queries, or checking
    the number of Gitaly calls.
    48f069ee
with_request_store.rb 525 Bytes