Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Make ActiveRecord queries thread-safe #26

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

mgomes
Copy link

@mgomes mgomes commented Mar 26, 2020

When using a threaded HTTP server like Puma, calling Model.establish_connection is dangerous. There is a chance the ActiveRecord connection is swapped by Casino itself and you'll get a Table doesn't exist error. In a really bad case though, Casino and the database we are connecting to may have a users table of the same name which could result in incorrect data being accessed.

This PR rewrites the connection to instead rely on a ConnectionPool which is thread-safe. Additionally it no longer requires a class to be meta-programmed and called -- it now just runs the SQL query directly.

I will work on getting the tests to pass.

@coveralls
Copy link

coveralls commented Mar 26, 2020

Coverage Status

Coverage decreased (-51.8%) to 48.214% when pulling cc53fc2 on church-initiative:bugfix/make-connections-thread-safe into 1227467 on rbCAS:master.

@mgomes mgomes changed the title Make ActiveRecord queries threadsafe Make ActiveRecord queries thread-safe Mar 26, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants