Apache with passenger gives error(Premature end of script headers) in development mode - ruby-on-rails

I'm using Apache + passenger for my rails application, The application is running fine in production mode except when the browser displays error message after every 2-3 clicks in development mode which goes off when i refresh the page.I'm using metal in my rails application which i see could be the reason but not sure if it is the only reason.
Error message on browser:
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
Please contact the server administrator, [no address given] and inform them of the time the error occurred, and anything you might have done that may have caused the error.
More information about this error may be available in the server error log.
Apache/2.2.16 (Ubuntu) Server at localhost Port 80
Apache log Error:
[Thu Dec 01 16:55:23 2011] [error] [client 127.0.0.1] Premature end of script headers: view_transactions, referer: http://localhost/admin_portal/1014978061/view_transactions
[ pid=660 thr=3078097552 file=ext/apache2/Hooks.cpp:822 time=2011-12-01 16:55:23.563 ]: The backend application (process 796) did not send a valid HTTP response; instead, it sent nothing at all. It is possible that it has crashed; please check whether there are crashing bugs in this application.
[ pid=796 thr=-608495398 file=utils.rb:176 time=2011-12-01 11:25:23.878 ]: *** Exception NoMethodError in application (undefined method `new' for Rails:Module) (process 796, thread #<Thread:0xb77631b4>):
from /home/brijendra/aptana_studio_3_workspace/wantsa/vendor/plugins/newrelic_rpm/lib/new_relic/control.rb:467:in `new_instance'
from /home/brijendra/aptana_studio_3_workspace/wantsa/vendor/plugins/newrelic_rpm/lib/new_relic/control.rb:54:in `instance'
from /home/brijendra/aptana_studio_3_workspace/wantsa/vendor/plugins/newrelic_rpm/lib/new_relic/agent.rb:167:in `logger'
I would be eager to post any other output if required and also suggestions to fix this issue.

I fixed this error by changing cache as true in my development.rb and it worked fine.

Related

Installed another Rails application on server and existing application stop working

I got below error when install another rails application on server.
App 970 stderr: Cannot execute "/home/ec2-user/.rvm/gems/ruby-2.3.0/gems/passenger-5.1.2/buildout/support-binaries/PassengerAgent": Permission denied (errno=13)
[ 2017-04-19 14:25:36.2735 898/7f6d6a5e4700 age/Cor/App/Implementation.cpp:304 ]: Could not spawn process for application /var/www/html/entertainoz: An error occurred while starting up the preloader.
Error ID: 7312b405
Error details saved to: /tmp/passenger-error-S9HJRx.html
Message from application: Cannot execute "/home/ec2-user/.rvm/gems/ruby-2.3.0/gems/passenger-5.1.2/buildout/support-binaries/PassengerAgent": Permission denied (errno=13)
I tried to find the issue but still not get it.

Getting websocket error code 1006 when trying to connect to Actioncable server

I'm building an app using Nativescript/Angular 2 and I'm also using a javascript library to use websockets connecting it with an Actioncable Rails app.
When trying to establish connection I get a websocket error code 1006 on the Nativescript log console and the connection gets closed.
I noticed that the initial HTTP (the handshake) request sends two values for Sec-WebSocket-Protocol on the header (actioncable-v1-json, actioncable-unsupported) but the headers in the response have only one value for Sec-WebSocket-Protocol which is 'actioncable-v1-json' and 'actioncable-unsupported' is missing.
I believe this error happens because of the missing protocol in the response.
Does anyone know how to add this header (actioncable-unsupported) to the handshake response? Or any other ideas of what is causing this error?
There is no error in the rails log, it just gets connected and then disconnected:
Started GET "/v1/cable/" [WebSocket] for 192.168.1.8 at 2017-04-02 17:04:06 -0700
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
Finished "/v1/cable/" [WebSocket] for 192.168.1.8 at 2017-04-02 17:04:06 -0700
The error message displayed on the Nativescript console is this:
CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] Opening WebSocket, current state is null, subprotocols: actioncable-v1-json,actioncable-unsupported 1491179483038
CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] ConnectionMonitor started. pollInterval = 3000 ms 1491179483042
CONSOLE LOG file:///app/tns_modules/nativescript-actioncable/lib/action_cable.js:46:33: [ActionCable] Socket was closed because: code: 1006 1491179483109
Thank you
I was having this issue and the issue was the cable.yml configuration.
We noticed that the staging environment had this value for url:
url: <%= ENV.fetch("REDIS_URL") { "redis://localhost:6379/1" } %>
Removing that value and actually other values fixed it for us.
New cable.yml staging config:
staging:
adapter: redis
Working!

Exception RuntimeError in Passenger RequestHandler's client socket (can't modify string; temporarily locked)

Receiving below error on rails application hosted on nginx:
Sending 502 response: application did not send a complete response
App 1462 stderr: [ 2015-xx-xx 15:10:29.2082 1494/XXXXXXXXXXXX(Worker 1) utils.rb:85 ]: *** Exception RuntimeError in Passenger RequestHandler's client socket (can't modify string; temporarily locked) (process 1494, thread XXXXXXXXXXXXX(Worker 1)):
App 1462 stderr: from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-5.0.13/lib/phusion_passenger/utils/unseekable_socket.rb:188:in `read'
App 1462 stderr: from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-5.0.13/lib/phusion_passenger/utils/unseekable_socket.rb:188:in `read'
[ 2015-09-09 15:10:29.2083 1423/7fa8af7fe700 age/Cor/Req/Utils.cpp:95 ]: [Client 6-19] Sending 502 response: application did not send a complete response
App 1462 stderr: from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-5.0.13/lib/phusion_passenger/message_channel.rb:177:in `read_scalar'
App 1462 stderr: from /usr/local/lib/ruby/gems/1.9.1/gems/passenger-5.0.13/lib/phusion_passenger/request_handler/thread_handler.rb:217:in `parse_session_request'
App 1462 stderr: from /usr/local/lib/ruby/gems/1.9.1/gems/passenger
Restarted VM and application but receiving same error.
Not sure what exactly causes this error. But as can be found from this link:
http://code.google.com/p/phusion-passenger/issues/detail?id=582
We reuse the same buffer over and over for receiving request data, for performance reasons. If your app is somehow able to use our buffer for receiving I/O data as well, in a different thread, then that would result in a race condition with the reporter error as a result.
One user reports resolution of similar problem here:
http://code.google.com/p/phusion-passenger/issues/detail?id=605
Indeed, I've narrowed it down to rails-master and/or rack-cache 1.0. When removing caching from latest version of rails (so it does not load rack-cache) everything works.
Hope it will be helpful

Rails app may be crashing passenger, not sure how to debug?

My app generates some image data on the fly and sends it back to the browser with send_data some_huge_blob, :type => 'image/png'. This works well enough in development mode, but in production with nginx/passenger in the mix it appears as if sometimes passenger just crashes. Here is the debug output in my nginx log
[ pid=596 thr=140172782794496 file=ext/common/ApplicationPool/Pool.h:1162 time=2011-07-25 23:15:14.965 ]: Exception occurred while connecting to checked out process 1428: Cannot connect to Unix socket '/tmp/passenger.1.0.589/generation-0/backends/ruby.kJRjXYuZteKoogZIufN8a2cDPdpbIlYmIr1hh3G9UV7GhKDB4pqZ5y0jR': Connection refused (111)
[ pid=596 thr=140172782794496 file=ext/common/ApplicationPool/Pool.h:685 time=2011-07-25 23:15:14.965 ]: Detaching process 1428
[ pid=596 thr=140172782794496 file=ext/common/ApplicationPool/../Process.h:138 time=2011-07-25 23:15:14.969 ]: Application process 1428 (0x2676ee0): destroyed.
[ pid=1405 thr=70178806733240 file=abstract_request_handler.rb:466 time=2011-07-25 23:15:14.982 ]: Accepting new request on main socket
2011/07/25 23:15:16 [error] 642#0: *96 upstream prematurely closed connection while reading response header from upstream, client: 173.8.216.57, server: app.somedomain.com, request: "GET /projects/4e2dee4c106a821bf2000008/revisions/1/assets/Layout2.psd/preview HTTP/1.1", upstream: "passenger:unix:/passenger_helper_server:", host: "app.somedomain.com"
Note that there is nothing in my production.log file that indicates the request even makes it to the app!
Any ideas? Or ideas as to how to debug this further? The connection refused bit is interesting...
For what it's worth, this is an Ubuntu image on a micro instance in AWS.

Nginx + Passenger - Uncaught exception in PassengerServer client thread

I've installed Passenger with Nginx for testing here and I keep getting this error after some thousand requests:
[ pid=57259 thr=0x40f07780 file=ext/nginx/HelperAgent.cpp:576 time=2010-12-15 14:04:25.876 ]: Uncaught exception in PassengerServer client thread:
exception: write() failed: Socket is not connected (57)
backtrace:
in 'void Client::forwardResponse(Passenger::SessionPtr&, Passenger::FileDescriptor&)' (HelperAgent.cpp:368)
in 'void Client::handleRequest(Passenger::FileDescriptor&)' (HelperAgent.cpp:502)
in 'void Client::threadMain()' (HelperAgent.cpp:595)
[ pid=57259 thr=0x40f07080 file=ext/nginx/HelperAgent.cpp:566 time=2010-12-15 14:04:26.416 ]: Couldn't forward the HTTP response back to the HTTP client: It seems the user clicked on the 'Stop' button in his browser.
I have 2 servers, and I was running haproxy+apache+mongrel on them, I switched one of them for haproxy+nginx+passenger (haproxy is only a backup for my testing, so I can redirect to the old schema quickly in case of fire).
So I noticed that my passenger dies after this message.
Im using ruby-ee 1.8.7, rails 2.3.5 and FreeBSD.
That turns out to be a FreeBSD kernel bug. We're slowly putting more workarounds in the Phusion Passenger codebase to work around this.

Resources