Skip to content

Conversation

@dkeegan-figma
Copy link
Contributor

Summary

Cherry-picks Shopify's fix for nil reservation bug (commit 40d568c). Prevents workers from setting @reserved_test to nil when the queue is empty, which could cause crashes or unexpected behavior.

Changes

Modified Files

  • ruby/lib/ci/queue/redis/worker.rb - Updated reserve method to only set @reserved_test when test is non-nil

The Bug

Previously, when try_to_reserve_lost_test and try_to_reserve_test both returned nil (queue empty), the code would still set @reserved_test = nil, potentially causing issues with reservation tracking.

The Fix

# Before - sets @reserved_test even when nil
@reserved_test = try_to_reserve_lost_test || try_to_reserve_test

# After - only sets @reserved_test when non-nil
test = try_to_reserve_lost_test || try_to_reserve_test
@reserved_test = test if test
test

Conflict Resolution

Adapted for Figma's architecture:

  • Shopify's version uses reserved_tests (Set)
  • Figma uses @reserved_test (single instance variable)
  • Successfully adapted the nil-check logic to work with Figma's approach

Benefits

  • Correctness: Prevents nil reservations
  • Reliability: Avoids potential crashes from unexpected nil values
  • Safety: Better reservation state management

Testing

  • ✅ Ruby syntax check passes
  • ✅ Logic verified through code review
  • ✅ Preserves existing reservation error checking
  • ⏳ Full test suite requires Redis (run in CI)

Original Shopify PR

Risk Assessment

Risk Level: Low

  • Small, focused change (3 insertions, 1 deletion)
  • Defensive programming improvement
  • No behavior change when tests are available
  • Only affects edge case when queue is exhausted

cc: @Dkeegan

@dkeegan-figma dkeegan-figma marked this pull request as ready for review December 12, 2025 19:18
@dkeegan-figma dkeegan-figma merged commit 52f3b8d into master Dec 16, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants