Draft: fix: unset SidekiqStatus on job failure

Changes

Fixed lib/gitlab/sidekiq_status/server_middleware.rb

  • Replaced the current implementation with a begin-ensure block pattern
  • The ensure block guarantees that SidekiqStatus.unset(job['jid']) is always called, even when exceptions are raised
  • This follows the same pattern used in other middleware like BatchLoader
  • The implementation is now cleaner and more concise (4 lines instead of 6)

Added test coverage in spec/lib/gitlab/sidekiq_status/server_middleware_spec.rb

  • Added a new test case: "stops tracking of a job even when an error is raised during job execution"
  • The test verifies that SidekiqStatus.unset is called even when the job raises an exception
  • Follows the same test pattern used in extra_done_log_metadata_spec.rb

Problem Solved

  • Before: If a job raised an exception, unset was never called, leaving orphaned status keys in Redis for 30 minutes
  • After: The ensure block guarantees cleanup happens regardless of whether the job succeeds or fails
  • This prevents SidekiqStatus.running?(job_id) from incorrectly returning true for failed jobs
Edited by Victor Prêté

Merge request reports

Loading