Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite Busy Exceptions not being treated as cache misses #241

Open
Th3-M4jor opened this issue Dec 4, 2024 · 3 comments
Open

SQLite Busy Exceptions not being treated as cache misses #241

Th3-M4jor opened this issue Dec 4, 2024 · 3 comments

Comments

@Th3-M4jor
Copy link

We're experimenting with using SolidCache backed by SQLite in production and found that SolidCache::Store::Failsafe does not include SQLite::Busy exceptions as a possible transient error that would be treated is if it were a cache miss.

Since this is something that could still theoretically occur with sharding and a reasonable busy timeout on SQLite configured, should this be added to the list of possible transient ActiveRecord errors?

@djmb
Copy link
Collaborator

djmb commented Dec 18, 2024

Oh interesting. I would expect the SQlite::BusyExceptions to be wrapped up as ActiveRecord::StatementTimeout, which we do rescue - see here.

Sounds like this is not working though - do you know why?

@Th3-M4jor
Copy link
Author

Th3-M4jor commented Dec 18, 2024

I'm actually seeing it be wrapped as a ActiveRecord::StatementInvalid when it happens.

I added the below code to a Rails initializer and it seems to solve the issue for us:

module PatchSolidCacheFailSafe
  private

  def failsafe(method, returning: nil)
    super
  rescue ActiveRecord::StatementInvalid => e
    raise e unless e.cause.is_a?(SQLite3::BusyException)

    Rails.logger.warn("Caught SQLite3::BusyException in SolidCache::Store::FailSafe. Treating as cache miss.")

    returning
  end
end

SolidCache::Store::Failsafe.prepend(PatchSolidCacheFailSafe)

Note: This is with Rails 7.2.2.1

@Th3-M4jor
Copy link
Author

Dug a little further and it seems that it's because 7-2-stable does not wrap SQLite3::BusyException as an ActiveRecord::StatementTimeout so the catch all in the abstract adapter will convert it to a StatementInvalid

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

No branches or pull requests

2 participants