Sachin
Sachin

Reputation: 1003

Websocket Rails | 504 response | Connection ends abruptly

I am using websocket-rails gem for handling messaging service for my application.

Tech Stack: Rails 4.2.5, Ruby 2.3.0p0, Passenger as app-server(Also tried with Puma), Thin as websocket server on port 3001, ngnix as web server and Websocket patch of gem 'websocket-rails', github: 'moaa/websocket-rails', branch: 'sync_fixes'

When an client hits the websocket server, it actively triggers the server event of client_connected and I can see on websocket_rails_server.log the message that I print, i.e.

"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"
"+++++++++++ WebsocketRails Client CONNECTED ++++++++++++++"
"++++++++++++++++++++++++++++++++++++++++++++++++++++++++++"

But, on client end it abruptly ends with response:

WebSocket connection to 'ws://beta.server.com/websocket' failed: Error during WebSocket handshake: Unexpected response code: 504

I have tried with every solution on Github issues as well as Stackoverflow related question, but no help yet.

My nginx config is as follows(if that's needed anyway):

server {
    listen 80;
    server_name beta.server.com;

    root /var/www/server-rails/current/public;

    proxy_cache_bypass 1;
    proxy_no_cache 1;

    location /websocket {
      proxy_pass http://localhost:3001/websocket;
      proxy_http_version 1.1;
      proxy_set_header  X-Real-IP  $remote_addr;
      add_header Access-Control-Allow-Origin *;                                                                                
      proxy_set_header Upgrade websocket;
      proxy_set_header Connection upgrade;
      proxy_set_header Host $host;
      proxy_set_header X-Real-IP $remote_addr;
      proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    }

    passenger_enabled on;
    passenger_sticky_sessions on;
    passenger_app_env staging;
}

Upvotes: 1

Views: 383

Answers (0)

Related Questions