Details
Description
The rails database connection pool use does not seems to use the autoreconnect=true jdbc url setting and some users experience the following error :
2008.08.26 09:37:40 ERROR rails.sonar
ActiveRecord::StatementInvalid (ActiveRecord::ActiveRecordError:
Communications link failure due to underlying exception:
-
- BEGIN NESTED EXCEPTION **
java.net.SocketException
MESSAGE: Broken pipe
STACKTRACE:
java.net.SocketException: Broken pipe
at java.net.SocketOutputStream.socketWrite0(Native Method)
at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:92)
at java.net.SocketOutputStream.write(SocketOutputStream.java:136)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2744)
at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1612)
at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:1723)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3277)
at com.mysql.jdbc.Connection.execSQL(Connection.java:3206)
at com.mysql.jdbc.Statement.executeQuery(Statement.java:1232)
at jdbc_adapter.JdbcAdapterInternalService$7.call(JdbcAdapterInternalService.java:647)
at jdbc_adapter.JdbcAdapterInternalService.withConnectionAndRetry(JdbcAdapterInternalService.java:241)
at jdbc_adapter.JdbcAdapterInternalService.execute_query(JdbcAdapterInternalService.java:641)
at jdbc_adapter.JdbcAdapterInternalServiceInvoker$execute_query_s_method_0_0.call(Unknown
Source)
at org.jruby.internal.runtime.methods.JavaMethod$JavaMethodNoBlock.call(JavaMethod.java:63)
at org.jruby.internal.runtime.methods.DynamicMethod.call(DynamicMethod.java:78)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:329)
at org.jruby.evaluator.ASTInterpreter.callNode(ASTInterpreter.java:649)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:324)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:170)
at org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:174)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:150)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:309)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:363)
at org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1120)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:370)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:170)
at org.jruby.runtime.InterpretedBlock.yield(InterpretedBlock.java:150)
at org.jruby.runtime.Block.yield(Block.java:114)
at org.jruby.evaluator.ASTInterpreter.yieldNode(ASTInterpreter.java:1850)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:509)
at org.jruby.evaluator.ASTInterpreter.rescueNode(ASTInterpreter.java:1556)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:468)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:170)
at org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:174)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:150)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:275)
at org.jruby.evaluator.ASTInterpreter.fCallNode(ASTInterpreter.java:1139)
at org.jruby.evaluator.ASTInterpreter.evalInternal(ASTInterpreter.java:370)
at org.jruby.evaluator.ASTInterpreter.eval(ASTInterpreter.java:170)
at org.jruby.internal.runtime.methods.DefaultMethod.interpretedCall(DefaultMethod.java:174)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:150)
at org.jruby.internal.runtime.methods.DefaultMethod.call(DefaultMethod.java:309)
at org.jruby.runtime.CallSite$InlineCachingCallSite.call(CallSite.java:363) ...
-
- END NESTED EXCEPTION **
Last packet sent to the server was 4 ms ago.: SELECT snapshots.`id` AS
t0_r0, snapshots.`created_at` AS t0_r1, snapshots.`project_id` AS
t0_r2, snapshots.`parent_snapshot_id` AS t0_r3, snapshots.`status` AS
t0_r4, snapshots.`purged` AS t0_r5, snapshots.`is
last` AS t0_r6, snapshots.`scope` AS t0_r7, snapshots.`qualifier` AS
t0_r8, snapshots.`root_snapshot_id` AS t0_r9, snapshots.`version` AS
t0_r10, projects.`id` AS t1_r0, projects.`name` AS t1_r1,
projects.`description` AS t1_r2, projects.`enabled` AS t1_r3
, projects.`scope` AS t1_r4, projects.`qualifier` AS t1_r5,
projects.`kee` AS t1_r6, projects.`root_id` AS t1_r7 FROM snapshots
LEFT OUTER JOIN projects ON projects.id = snapshots.project_id WHERE
(islast=1 and projects.enabled=1 and parent_snapshot_id is
null and snapshots.scope='PRJ' and snapshots.status='P') ):
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/connection_adapters/abstract_adapter.rb:128:in
`log'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-jdbc-adapter-0.8.2/lib/active_record/connection_adapters/jdbc_adapter.rb:537:in
`execute'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-jdbc-adapter-0.8.2/lib/active_record/connection_adapters/jdbc_adapter.rb:597:in
`select'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-jdbc-adapter-0.8.2/lib/active_record/connection_adapters/jdbc_adapter.rb:522:in
`jdbc_select_all'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/associations.rb:1189:in
`select_all_rows'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/associations.rb:1044:in
`find_with_associations'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/associations.rb:1042:in
`catch'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/associations.rb:1042:in
`find_with_associations'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/base.rb:995:in
`find_every'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/activerecord-1.15.6/lib/active_record/base.rb:418:in
`find'
/var/wimba/sonar-1.4/war/sonar-web/app/models/snapshot.rb:32:in
`last_enabled_projects'
/var/wimba/sonar-1.4/war/sonar-web/app/controllers/project_controller.rb:55:in
`index'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:1101:in
`perform_action'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:696:in
`call_filters'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:688:in
`perform_action_with_filters'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in
`perform_action_with_benchmark'
file:/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/lib/jruby-complete-1.1.2.jar!/benchmark.rb:293:in
`measure'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/benchmarking.rb:66:in
`perform_action_with_benchmark'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/rescue.rb:83:in
`perform_action_with_rescue'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:435:in
`process'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/filters.rb:684:in
`process_with_filters'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/session_management.rb:114:in
`process_with_session_management_support'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/actionpack-1.13.6/lib/action_controller/base.rb:334:in
`process'
/var/wimba/sonar-1.4/war/sonar-web/WEB-INF/gems/gems/rails-1.2.6/lib/dispatcher.rb:41:in
`dispatch'
:1
After some researches, only the rails part is causing problesm since it is not using a database connections pool.
The fix would be to upgrade to rails 2.x so that we can simulate a database conections pool use :
if defined?($servlet_context)
require 'action_controller/dispatcher'
ActionController::Dispatcher.after_dispatch do
ActiveRecord::Base.clear_active_connections!
end
end
We would also have to set the testOnBorrow pool setting to test the connection is alive when the it is taken from the pool
Currently a few refresh buttons hit is correcting hte problems ar rails reconnects to the database.
- config/initializers/close_connections.rb
if defined?($servlet_context)
require 'action_controller/dispatcher'
ActionController::Dispatcher.after_dispatch do ActiveRecord::Base.clear_active_connections! end end We would also have to set the testOnBorrow pool setting to test the connection is alive when the it is taken from the pool Currently a few refresh buttons hit is correcting hte problems ar rails reconnects to the database.