Skip to content

Conversation

@p-schlickmann
Copy link
Contributor

Issue: #602
Flake: recurring_tasks_test.rb
Failed run: https://github.com/rails/solid_queue/actions/runs/18916883193/job/54002506057
Instructions to validate the fix locally: #678

Summary

I found a race condition in recurring_tasks_test.rb which tries to stop the supervisor twice. Once inside the test and once again in teardown.

When synchronized enough, the first shutdown worked, and the second one tried to stop a process that had already exited. That second attempt escalated to a KILL instead of a clean TERM, which is why the assertion failed in CI.

The fix makes sure we only stop the supervisor once, removing the double-shutdown race.

@p-schlickmann p-schlickmann force-pushed the recurring-flaky-tests branch 2 times, most recently from 393f0ec to 7ee0213 Compare November 17, 2025 15:18
@p-schlickmann
Copy link
Contributor Author

Green CI = instant dopamine 🤩

SolidQueue::Process.destroy_all
SolidQueue::Job.destroy_all
SolidQueue::RecurringTask.delete_all
JobResult.delete_all
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed this from teardown since it's already handled in test_helper.rb teardown


terminate_process(pid)
wait_for_registered_processes(0, timeout: SolidQueue.shutdown_timeout)
sleep SolidQueue.shutdown_timeout
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this extra sleep necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point! I guess I was being extra cautious while debugging this, it seemed worth it because shutdown_timeout is only 2 seconds. But I tested locally and it runs fine without it. Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thank you so much!

end
end

# no need to stop @pid supervisor - that will be handled in teardown
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! I think we can remove this comment, as I think most people won't wonder about this 🤔

@rosa rosa merged commit b61bbdf into rails:main Nov 17, 2025
52 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.

2 participants