Erreur de connexions simultanées des passagers

J’ai un serveur de production (Nginx + Passenger). Lorsque j’essaie d’ ab -n 3 -c 3 myhost.ru/ partir d’un autre ordinateur, je reçois ce ab -n 3 -c 3 myhost.ru/ d’erreur dans mon nginx error.log:

 [ pid=21160 thr=139775297914624 file=ext/nginx/HelperAgent.cpp:584 time=2011-08-31 15:25:49.22 ]: Uncaught exception in PassengerServer client thread: exception: Cannot read response from backend process: Connection reset by peer (104) backtrace: in 'void Client::forwardResponse(Passenger::SessionPtr&, Passenger::FileDescriptor&, const Passenger::AnalyticsLogPtr&)' (HelperAgent.cpp:330) in 'void Client::handleRequest(Passenger::FileDescriptor&)' (HelperAgent.cpp:510) in 'void Client::threadMain()' (HelperAgent.cpp:603) [ pid=21249 thr=15884760 file=utils.rb:176 time=2011-08-31 15:25:49.022 ]: *** Exception PGError in application (server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. ) (process 21249, thread #): from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `exec' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `block in clear_cache!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `each_value' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `clear_cache!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:303:in `disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `each' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:35:in `block in disconnect_with_synchronization!' from /home/deployer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:34:in `disconnect_with_synchronization!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `block in clear_all_connections!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `each_value' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `clear_all_connections!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `clear_all_connections!' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/utils.rb:398:in `before_handling_requests' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:204:in `start_request_handler' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:170:in `block in handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/utils.rb:479:in `safe_fork' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:180:in `start' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:128:in `start' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize' from :10:in `synchronize' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/helper-scripts/passenger-spawn-server:99:in `' 2011/08/31 15:25:49 [error] 21197#0: *41173 upstream prematurely closed connection while reading response header from upstream, client: 78.47.253.164, server: yandex.ru, request: "GET / HTTP/1.0", upstream: "passenger:unix:/passenger_helper_server:", host: "yandex.ru" [ pid=21160 thr=139775298115328 file=ext/nginx/HelperAgent.cpp:584 time=2011-08-31 15:25:49.31 ]: Uncaught exception in PassengerServer client thread: exception: Cannot read response from backend process: Connection reset by peer (104) backtrace: in 'void Client::forwardResponse(Passenger::SessionPtr&, Passenger::FileDescriptor&, const Passenger::AnalyticsLogPtr&)' (HelperAgent.cpp:330) in 'void Client::handleRequest(Passenger::FileDescriptor&)' (HelperAgent.cpp:510) in 'void Client::threadMain()' (HelperAgent.cpp:603) 2011/08/31 15:25:49 [error] 21197#0: *41172 upstream prematurely closed connection while reading response header from upstream, client: 78.47.253.164, server: yandex.ru, request: "GET / HTTP/1.0", upstream: "passenger:unix:/passenger_helper_server:", host: "yandex.ru" [ pid=21257 thr=15884760 file=utils.rb:176 time=2011-08-31 15:25:49.032 ]: *** Exception PGError in application (server closed the connection unexpectedly This probably means the server terminated abnormally before or while processing the request. ) (process 21257, thread #): from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `exec' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:276:in `block in clear_cache!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `each_value' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:275:in `clear_cache!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/postgresql_adapter.rb:303:in `disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:202:in `block in disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `each' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:201:in `disconnect!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:35:in `block in disconnect_with_synchronization!' from /home/deployer/.rvm/rubies/ruby-1.9.2-p180/lib/ruby/1.9.1/monitor.rb:201:in `mon_synchronize' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activesupport-3.1.0/lib/active_support/core_ext/module/synchronization.rb:34:in `disconnect_with_synchronization!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `block in clear_all_connections!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `each_value' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_pool.rb:395:in `clear_all_connections!' from /home/deployer/yandex.ru/shared/bundle/ruby/1.9.1/gems/activerecord-3.1.0/lib/active_record/connection_adapters/abstract/connection_specification.rb:123:in `clear_all_connections!' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/utils.rb:398:in `before_handling_requests' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:204:in `start_request_handler' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:170:in `block in handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/utils.rb:479:in `safe_fork' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:165:in `handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:180:in `start' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/rack/application_spawner.rb:128:in `start' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:253:in `block (2 levels) in spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:132:in `lookup_or_add' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:246:in `block in spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:82:in `block in synchronize' from :10:in `synchronize' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server_collection.rb:79:in `synchronize' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:244:in `spawn_rack_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:137:in `spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/spawn_manager.rb:275:in `handle_spawn_application' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:357:in `server_main_loop' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/lib/phusion_passenger/abstract_server.rb:206:in `start_synchronously' from /home/deployer/.rvm/gems/ruby-1.9.2-p180/gems/passenger-3.0.7/helper-scripts/passenger-spawn-server:99:in `' 

J’ai trouvé la solution moi-même. Il doit y avoir nginx.conf passenger_spawn_method conservative smart-lv2 dans nginx.conf au lieu de default passenger_spawn_method conservative smart-lv2 .

Vous allouez ou gérez vos propres connexions / pools de bases de données?

Passenger reconnecte le pool de firebase database ActiveRecord par défaut pour chaque travailleur en arrière-plan une fois qu’il a sortingché.

Toutefois, les autres ressources ou les connexions de firebase database gérées manuellement doivent être configurées / reconnectées manuellement pour chaque travailleur après un échec.

J’ai écrit un article de blog détaillé expliquant comment résoudre ce problème: http://blog.winfieldpeterson.com/2011/01/06/passenger-resource-collision/

Cela ressemble à ce que vous rencontrez, plusieurs employés essayant de partager une connexion de firebase database unique et produisant des erreurs sous charge en raison de conflits de ressources.

Nous avons rencontré le même problème avec Rails 3.1, pg, ruby ​​1.9.3 et Apache + Passenger 3.0.9. La mise à niveau vers Rails 3.1.1 semble résoudre ce problème.

https://github.com/rails/rails/issues/1339