ActiveRecord connection does not reconnect when using Thin/Sinatra but works fine with just Sinatra.
-
hbeaver (at gmail)
RESOLUTION?
I moved the "before do" into extended Sinatra::Default class as opposed to model and issue was resolved. However, this does not explain why mongrel will create a new connection auto-magically whereas thin will not. Please see 2 attached tcpdumps named appropriately, 'thin_no_reconnect_example.dump' and 'mongrel_reconnect_example.dump'.
In both, the server has just been started and then a HTTP request is made to a one line action that does Model.find(:first). In both, a mysql connection is created ok after server is started. After approx. 10 seconds (because of the wait_timeout setting in the ticket I mentioned yesterday) mysql will sent a FIN/ACK (disconnect). Shortly thereafter another HTTP request is made to server. Mongrel creates yet another connection, but thin will not. I am not certain if this is a bug or just the nature of thin.
I thought it important to present this information.
Thanks again,
Hank -
Nate Wiger
I'm running into this exact same problem with thin/sinatra. Don't see it with thin/rails.
Any ideas?
-
hbeaver (at gmail)
- Assigned user cleared.
As mentioned above, I resolved this issue by moving ActiveRecord::Base.connection.verify! into Sinatra class before do block:
class NewApp < Sinatra::Default before do ActiveRecord::Base.connection.verify! end ... end #end of Sinatra class -
Nate Wiger
- Assigned user set to macournoyer
Just to follow-up, this approach has been working for me for some time. Based on the AR docs, the "correct" call which will handle multiple connections, etc, is:
before do ActiveRecord::Base.verify_active_connections! endI'm not sure if this is a bug in Thin per se, but it would still be interesting to understand why this happens with Thin/Sinatra as opposed to Mongrel or Thin/Rails.
-
Conny Brunnkvist
- Milestone order changed from 0 to 0
Same problem here.
Works when running in foreground but as soon as either of "-s 1" or "servers: 1" is set, ActiveRecord is can't connect.
-
Conny Brunnkvist
I wonder if we don't need to simply ActiveRecord::Base.establish_connection after forking.. but then, why wouldn't reconnect! work? I gave up on this one, will try again later perhaps.
Please Sign in or create a free account to add a new ticket.
With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.
