Rails 5 ActionCable fails to upgrade to WebSocket on Elastic Beanstalk - ruby-on-rails

For context, I've already tried to implement many answers regarding nginx (such as this one) to no success. This appears to be an issue related to nginx that isn't explored in other answers.
Using Rails 5.2 and Docker on a multicontainer EBS, WebSocket connections are failing. This failure only occurs when deployed and the same configuration works as expected locally.
I am using the Postgres adaptor with ActionCable
Problem Description:
My website is deployed to EBS and displays information just fine. My Postgres instance is connected and working as expected. However, these errors occur on WebSocket enabled pages:
In browser:
When I go to my SSL enabled site, a notice appears in the JS console:
The connection to wss://redacted.com/cable was interrupted while the page was loading.
Firefox can’t establish a connection to the server at wss://redacted.com/cable.
(This message repeats every ~5s)
Rails server logs:
Failed to upgrade to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: keep-alive, HTTP_UPGRADE: )
Finished "/cable/"[non-WebSocket] for <redacted IP> at 2018-02-28 02:49:03 +0000
(This message repeats every ~5s)
Prior research
Error codes:
Others in this situation note that their console throws a 400 - Bad handshake error (or similar). This is not the case here.
nginx (important):
As well, others seem to think that nginx is to blame. However, I cannot access nginx within my EBS instance. Any call for nginx results in service nginx not found and any modification of an nginx file via .ebextensions fails.
It's worth noting that I have no nginx Docker image or configuration whatsoever. I'm trying to modify EBS' built-in nginx configuration. To get to this point (where my website loads but WebSockets don't work), I have not configured nginx at all.
Troubleshooting steps taken
Changed EBS load balancer from HTTP to TCP
Modification of nginx (see above)
Specifying the ActionCable server URL in my production.rb
Specifying allowed WebSocket hosts in production.rb
Changing cable.yml adapters and hosts

Related

Rails app on AWS Elastic Beanstalk: Bad nginx config

So I have a rails application that I built and deployed via AWS Elastic Beanstalk a few months ago. The project was put on hold so I terminated the environment, expecting to be able to re-deploy when we returned to this project.
Despite my app still running just fine on my local dev environment, I cannot get it to deploy. The error from my eb-activty.log:
PG::ConnectionBad: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
The database is a standalone AWS RDS instance that I can successfully test the connection to, so I know its running. I have added the requisite environment variables and configured my database.yml accordingly. To be clear, this is an application that used to work. I hadn't made any changes between the time I terminated the environment and when I went to re-deploy.
The root problem seems to be that nginx isn't being configured properly, as trying to access the server returns:
502 Bad Gateway
nginx/1.12.1
and when I check the nginx error.log its filled with errrors like this:
2018/09/19 14:12:35 [crit] 3069#0: *653 connect() to unix:///var/run/puma/my_app.sock failed (2: No such file or directory) while connecting to upstream, client: 172.31.47.147, server: _, request: "GET / HTTP/1.1", upstream: "http://unix:///var/run/puma/my_app.sock:/", host: "172.31.47.147"
Naturally, I googled my error, and found this stackoverflow post.
I've tried adding these suggested lines from the top-rated answer to my puma.rb
bind "unix:///var/run/puma/my_app.sock"
pidfile "/var/run/puma/my_app.sock"
Which caused no change at all.
I made sure to try the other suggestions, including having a direct look at the nginx configuration file. I did find that there's no upstream set up in the config. As best as I can see, the nginx aspect of the deployment pipeline is automated by Elastic Beanstalk so clearly something else I've set must be incorrect.
I've found that under no circumstances can I get the app to deploy using eb deploy I can only make changes by creating a new environment each time. I've recreated the app countless time, experimenting with different settings, versions of gems and packages, different ruby versions...etc. All in all, I still can't affect change on the error, I can't even get a new error! just the same PG:ConnectionBad or 502 bad gateway depending on if I look from console or browser.
From my googling I've come under the impression that this is related to puma in some regard but puma is a bit of a black box for me.
I'm feeling pretty lost here, I'd really appreciate any guidance you'd be willing to share. Feel free to ask for more info from any log or file, I'm happy to provide more detail. Thanks in advance!
Could be an RDS security group, is it configured to reach your elb?
You could also try cloning the db, to make sure its not sure weird database issue with old one, and try connecting to that.
So this wont be a very helpful answer as I never did resolve the problem. I didn't want to just leave this thread hanging though.
I ended up just creating a new rails environment, re-adding all the gems and porting my controllers/views/models/routes. Once I did that I was able to deploy without issue.
I can confirm that the issue wasn't with the security groups or the database itself. The fresh rails app was able to access the RDS instance without issue.
Thank you all for your comments and attemtps to help, it is much appreciated!

Trying to setup Neo4j 3.2.0 in ubuntu server

I am trying to setup Neo4j version 3.2.0 in the ubuntu server 14.04.2 LTS
Downloaded the tar and extracted the folder, edited the config file to update the port to 4444, for the time being disabled the bolt connector, listen_address to 0.0.0.0 for the http connector, authentication also disabled just to get started.
bolt connector is updated with the port 7687 even though it is disabled as i was trying earlier with it enabled.
Now when i try to connect to the http://serverip:4444/browser, it says Database access not available and shows me the login screen with host prefilled bolt://serverip:7687
Also I see this error on the console window
WebSocket connection to ws://serverip:7687/
failed: Error in connection establishment:
net::ERR_CONNECTION_TIMED_OUT
Dont understand the issues here, please help me out. I am not sure why is it trying to do a WS to the port assigned to the bolt, when it is disabled at the first place.
Regards
There's a bit of juggling going on for HTTP connector support between the browser and the driver being used, a handoff which isn't complete, and the state of things is the browser is only supporting bolt connections right now.
The javascript bolt driver is being upgraded to handle http connections, I think, so you may need to wait until the next 3.2.x release to use the http connector again.
I think this issue should be tracking it.

Production server using an outdated release of capistrano

I deploy new version via capistrano to a Ubuntu 14.04 server and now Unicorn + Nginx setup is referring to inexistent release. I get the ActionView::MissingTemplate and also a I18n::InvalidLocaleData because it failed to load the devise.en.yml file.
I pretty much followed this repo. I already restart nginx and unicorn but still gives me the same error. It's searching on a release/release_timestamp that no longer exists
You can at least confirm that Nginx is not part of the problem by directly connecting to the port or socket that Unicorn is listening on from within the server.
If Unicorn is running on a socket, see Can Curl send requests to sockets?.

AWS OpsWorks: Successful Ruby on Rails default layer deployment shows 404 error in browser

Didn't deployed Rails application in AWS OpsWorks. Totally confused how to do this! Could anyone tell me how many instance required to deploy a RoR application?
I have created "Rails App Server" instance and it's looks fine. And here I used nginx and Unicorn as Rails Stack.
After that I've added a application from a git repo. Then deployed that application. And logs showing it's deployed successfully.
But in Public IP it's showing 404 Not Found Error - nginx!
Any help would be appreciable.
I had this issue, and it turned out that the default virtual host /etc/nginx/sites-enabled/000-default symbolic link was not getting removed during deployment.
The 404 was actually nginx looking for a public root of whatever was in the default virtual host, as seen in /var/logs/nginx/error.log
2015/12/23 21:46:05 [error] 3839#0: *15 "/var/www/nginx-default/index.html" is not found (2: No such file or directory), client: 127.0.0.1, server: rails-app1, request: "GET / HTTP/1.1", host: "localhost"
Worse, it comes back after every OpsWorks deployment. Removing that link fixed the problem for me.
To make the fix sustainable and automated, I added a custom recipe to the Deploy lifecycle event for the Rails App Server layer, called custom-cookbook::delete-default-site. The recipe looks like this:
file '/etc/nginx/sites-enabled/000-default' do
action :delete
end
service 'nginx' do
action :reload
end
Check process list for unicorn and its log files. Deployment doesn't fail for some reason if unicorn master process doesn't start.

Deployed Rails3 but not showing up outside of server

I just deployed my Rails3 app to a linux server with Capistrano and Unicorn using mysql2. I keep getting the error "Oops! Google Chrome could not connect to 172.16.128.125" when trying to access the app in a browser.
What is weird is that I see no errors in the ./log/production.log file and if I use lynx on the server, I can render all pages of the app.
What am I missing? It works locally on the server but not outside the server.
Sounds like you might not have Apache running, or port 80 may not be reachable on that machine due to firewalling or routing issues.

Resources