Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error when deployed: "Error during WebSocket handshake: Unexpected response code: 404" #22871

Closed
KeithP opened this issue Dec 31, 2015 · 6 comments

Comments

@KeithP
Copy link
Contributor

KeithP commented Dec 31, 2015

When attempting to deploy the simple chat example https://github.com/HectorPerez/chat-in-rails5
to a single EC2 instance on AWS we get 'Error during WebSocket handshake: Unexpected response code: 404'. This works locally with RAILS_ENV=production but fails when deployed.

Steps to reproduce:

  1. Clone https://github.com/HectorPerez/chat-in-rails5

  2. Add redis install script by adding .ebextensions/ruby.config like this: https://gist.github.com/KeithP/08b38189372b7fd241e5#file-ebextensions-redis-config ; Git commit and deploy.

  3. Use Elastic Beanstalk to spin up a single instance thus:

eb create dev-env -p “64bit Amazon Linux 2015.09 v2.0.4 running Ruby
2.2 (Puma)” –single -i t2.micro --envvars
SECRET_KEY_BASE=g5dh9cg614a37d4bdece9126b42d50d0ab8b2fc785daa1e0dac0383d6387f36b
  1. Open in a browser, inspect and see this repeating error in the console:
application-a57354de3399cd895ca366df9bd7316ab69e81d266b63be7d7be563ebc78ab9d.js:27 
WebSocket connection to ‘ws://dev-env-y2e5dcrxqk.elasticbeanstalk.com/cable’ failed: 
Error during WebSocket handshake: Unexpected response code: 404

chatroom2

Check the logs and verify redis installed and started ok

This is also asked on stackoverflow: http://stackoverflow.com/questions/34536926/rails-5-0-0-beta1-activecable-error-during-websocket-handshake-unexpected-resp

@rafaelfranca
Copy link
Member

Is not this Elastic Beanstalk rejecting ws:// requests?

@rafaelfranca rafaelfranca added this to the 5.0.0 milestone Jan 6, 2016
@KeithP
Copy link
Contributor Author

KeithP commented Jan 6, 2016

@rafaelfranca not sure. Someone had success deploying to a single instance hosted on Cloud9, so probably AWS specific.
We tried adding proxy config for NGINX (https://gist.github.com/aku/5466527) but no joy.

The server production.log shows two "Started GET /cable" for every one "Finished /cable" call (strange?).
There are no DEBUG messages from ActionCable, so no clues. Normally we see lots of DEBUG messages for a 404 (can we have more logging?):

/var/app/containerfiles/logs/production.log

...
INFO -- : Processing by RoomsController#show as HTML
DEBUG -- : �[1m�[36mMessage Load (0.1ms)�[0m �[1m�[34mSELECT "messages".* FROM "messages"�[0m
INFO -- : Rendered collection (0.0ms)
INFO -- : Rendered rooms/show.html.erb within layouts/application (0.5ms)
INFO -- : Completed 200 OK in 2ms (Views: 1.2ms | ActiveRecord: 0.1ms)
INFO -- : Started GET "/cable" for xxx.xxx.xxx at 2016-01-01 17:28:26 +0000
INFO -- : Started GET "/cable/" for xxx.xxx.xxx at 2016-01-01 17:28:26 +0000
INFO -- : Finished "/cable/" for xxx.xxx.xxx at 2016-01-01 17:28:26 +0000
...

@KeithP
Copy link
Contributor Author

KeithP commented Jan 9, 2016

We got this working using this proxy config for NGINX : https://gist.github.com/KeithP/f8534c04d20c2b4e4b1d. In future to make this easier to troubleshoot can we add to the documentation and / or add more logging?

@maclover7
Copy link
Contributor

Feel free to submit a PR adding more error logging. I do think the source of error though is AWS' handling of websockets.

@KeithP
Copy link
Contributor Author

KeithP commented Jan 27, 2016

Thanks, PR #23274 is submitted for this

@dhh dhh removed this from the 5.0.0 milestone Feb 10, 2016
@maclover7
Copy link
Contributor

Closing due to #23274 being merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants