The ElasticBeanstalk is an Application Load Balancer configuration. It's a Ruby on Rails, with Passenger, Puma and NGINX (Default Ruby AWS Stack).
I'm forcing ssl, and I have everything working perfectly, except for the websockets, that seems to be (blocked|discarded|broken).
The first error is displayed in the console: (URL is my domain)
WebSocket connection to 'wss://<URL>/cable' failed: WebSocket is closed before the connection is established.
This request fails with (OPCODE -1)
in the frontend.
By checking the server logs, I have access.log
that's showing:
/cable"499
which is not a very descripting error.
And the rails production.log
shows:
Started GET "/cable/" [WebSocket] for 152.170.14.251 at 2018-05-28 21:01:27 +0000
Successfully upgraded to WebSocket (REQUEST_METHOD: GET, HTTP_CONNECTION: upgrade, HTTP_UPGRADE: websocket)
Registered connection (Z2lkOi8vYXNlc29yLWFwcC9JZGVudGl0eS81:Z2lkOi8vYXNlc29yLWFwcC9Vc2VyLzI)
WebSocket error occurred: wrong number of arguments (given 2, expected 1)
Sometimes I saw this other error:
NoMethodError: undefined method `+' for nil:NilClass
File "/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/websocket-driver-0.7.0/lib/websocket/driver/hybi.rb" line 11 in generate_accept
File "/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/websocket-driver-0.7.0/lib/websocket/driver/hybi.rb" line 76 in initialize
File "/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/websocket-driver-0.7.0/lib/websocket/driver.rb" line 160 in new
File "/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/websocket-driver-0.7.0/lib/websocket/driver.rb" line 160 in rack
File "/opt/rubies/ruby-2.5.1/lib/ruby/gems/2.5.0/gems/actioncable-5.2.0/lib/action_cable/connection/client_socket.rb" line 47 in initialize
And that file showed that a key is missing.
By following that error I found this issue:
That lead me to this final file:
File variable that seems to be missing
That finally lead me to this configurations that might be the ones missing:
After a lot of investigation I ended up in the gem source code, and looks like the encoding of some characters is failing and creating a weird string that ActionCable is not able to parse: