On a server with nginx and a unicorn, I have rails configured to connect to two different databases. With a small load, web requests to the endpoints that access the second rail database return the results of other requests.
For example, if there are simultaneous calls to http://example.com/user/111/address and http://example.com/user/222/address , sometimes the address for user 222 will be returned for BOTH calls, and sometimes it will return address for user 111 when accessing BOTH.
Entity for an address is very simple.
class UserController < ApplicationController before_filter :load_user def address address = @user.address render json: address, status: 200 end private def load_user @user = User.find params[:id] end end
The User and Address models have access to the second database and inherit from the base class that connects to this database:
class OtherDbActiveRecord < ActiveRecord::Base self.abstract_class = true establish_connection "#{Rails.env}_other_db"
Is there a way to connect to the second db that I am missing? What can cause ActiveRecord to return results for another query?
source share