Failsafe on ActiveRecord::ConnectionFailed - #317
Conversation
A terminated cache database connection raises ActiveRecord::ConnectionFailed, a subclass of ActiveRecord::StatementInvalid added in Rails 7.1. It wasn't in TRANSIENT_ACTIVE_RECORD_ERRORS, so instead of degrading to a cache miss the error propagated to the caller. Add it alongside the other transient connection errors and cover it with the failure safety behavior. Fixes: rails#307
|
Reviewed both this and #308. Ran each locally on Ruby 3.4.8 against sqlite: #308 is 400 runs / 0 failures, this one 405 runs / 0 failures. The production diff is byte identical in both, so the only thing to decide is the tests. I think the best outcome is a merge of the two, and I say that as the person who suggested the signature this PR uses. #308's helper naming is better than mine. I proposed The most valuable test here is not the ConnectionFailed one. It is So concretely: take #308 as the base, then rebase this one down to Two small things if this one is what gets merged instead:
Nothing blocking in either. On the timeline correction, thanks, you are right, and |
ded0138 to
de40265
Compare
|
Thanks for the careful review, agreed on all points. I rebased this on top of #308: Ajay's commit is included unchanged, so #308 should merge first and keeps priority. This PR is now down to |
Fixes #307
Stacked on #308 by @ajaynomics: that commit is included here unchanged and should merge first. Once it lands, the diff of this PR is only
test/unit/failsafe_test.rb.#308 adds
ActiveRecord::ConnectionFailedtoTRANSIENT_ACTIVE_RECORD_ERRORSand runs the wholeFailureSafetyBehavioragainst it. This PR adds the error handler side of the contract inSolidCacheFailsafeErrorsTest:ConnectionFailedreaches theerror_handler, withreturning: niland the exception instance.ConnectionFailedis re-raised when the handler raises.StatementInvalidandNoDatabaseErrorstill propagate.ConnectionFailed < QueryAborted < StatementInvalidandNoDatabaseError < StatementInvalid, so these are the nearest neighbours of the listed classes; the point of the list (Using Solid Cache for low-level caching produceswarning -- already initialized constant#182) is not to hide configuration errors or bugs behind a cache miss, and this test keeps that boundary explicit.The tests use
emulating_errorsfrom #308.Verified locally on SQLite: full suite green, and
test_connection_failed_is_passed_to_the_error_handlererrors without the one-line change tofailsafe.rb.