WebSocketBundle icon indicating copy to clipboard operation
WebSocketBundle copied to clipboard

Secure connection on heroku

Open Leggy7 opened this issue 8 years ago • 4 comments

I put a project on heroku and configured all the stuff accordingly to what I found here.

My procfile looks like this web: bin/start-stunnel $(composer config bin-dir)/heroku-php-apache2 web/

My config_prod.yml looks like this

# Web Socket Configuration!
gos_web_socket:
    server:
        port: 8443        #The port the socket server will listen on
        host: 127.0.0.1   #The host ip to bind to

I set stunnel to enabled, called connection from the client with var websocket = WS.connect("wss://my_app.herokuapp.com:8080"); and yet receiving the following error message when trying to connect:

VM1321:37 WebSocket connection to 'wss://my_app.herokuapp.com:8080/' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSEDWrappedWebSocket @ VM1321:37a._construct @ autobahn.min.js:62a.Session @ autobahn.min.js:63a._connect @ autobahn.min.js:78a.connect @ autobahn.min.js:83GosSocket.connect @ gos_web_socket_client.js:33GosSocket @ gos_web_socket_client.js:27connect @ gos_web_socket_client.js:108(anonymous function) @ (index):38 (index):45 Disconnected for Connection could not be established. with code 3

To put the server in listening I just accessed the bash with heroku run bash on my application and run the canonical

bin/console gos:websocket:server

and the message is

[2016-12-14 11:24:46] websocket.INFO: Starting web socket [2016-12-14 11:24:46] websocket.INFO: Launching Ratchet on 127.0.0.1:8080 PID: 6

which sounds good but, actually, I don't know if there is any kind of issue with the heroku bash which prevents this from working properly..

Is there anything I should check out to understand if I missed something?

EDIT: Apparently there are no traces of connection. The only clue I have is the launch message when running the server. Honestly I don't know how to debug this any longer. I also tried to run directly the bin/console gos:websocket:server by heroku run [cmd] but the result is the same.

Leggy7 avatar Dec 14 '16 11:12 Leggy7

Can you check your firewall for incoming connection, may be a firewall are blocking it (journalctl -xe) and try to connect you will see if the connection is rejected

jjsaunier avatar Dec 14 '16 15:12 jjsaunier

I think I cannot run that command on heroku shell, it says

bash: journalctl: command not found

By the way I don't think this could be the scenario since it should be configured to allow incoming connections (at least on certain ports).

By the way I opened a question on SO with some further consideration. Take a look, maybe you could confirm my doubts.

Leggy7 avatar Dec 14 '16 16:12 Leggy7

Hi, Kindly check this wiki page for SSL https://github.com/GeniusesOfSymfony/WebSocketBundle/wiki/Set-up-Gos-Web-Socket-Bundle-in-AWS-(Production)-with-SSL

robinkoikkara avatar Jan 29 '17 06:01 robinkoikkara

I checked with all my kindness the link above and also made some step forward with heroku. I upgaded my account to have access to ssl configuration, got a dummy certificate and (I guess) configured everything in the right way. The problem is just the same, nothing changed.

According to your link the thing I made differently are:

  • firewall configuration (no idea)

  • setting up stunnel. I just configured a buildpackage on heroku so that now I see on deploy:

remote: -----> Preparing runtime environment... remote: -----> Checking for additional extensions to install... remote: -----> stunnel app detected

I launch the websocket server from remote doing heroku run php bin/console gos:websocket:server

so I can read following output

Running php bin/console gos:websocket:server on notitek... up, run.1366 (Hobby)
[2017-02-02 13:21:14] websocket.INFO: Starting web socket
[2017-02-02 13:21:14] websocket.INFO: Launching Ratchet on localhost:8443 PID: 4

Heroku logs does not say anything

2017-02-02T13:57:00.732954+00:00 heroku[router]: at=info method=GET path="/js/autobahn.min.js" host=notitek.herokuapp.com request_id=ad94bb40-4351-4c43-86b7-62b7af603b1b fwd="xxx.xxx.xxx.xxx" dyno=web.1 connect=0ms service=2ms status=200 bytes=32265 2017-02-02T13:57:00.987676+00:00 app[web.1]: 10.158.162.94 - - [02/Feb/2017:13:57:00 +0000] "GET /js/gos_web_socket_client.js HTTP/1.1" 200 2709 "https://notitek.herokuapp.com/" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36 2017-02-02T13:57:00.995673+00:00 heroku[router]: at=info method=GET path="/js/gos_web_socket_client.js" host=notitek.herokuapp.com request_id=f3eb6343-8a4c-45b0-b963-ddd10345afc3 fwd="xxx.xxx.xxx.xxx" dyno=web.1 connect=1ms service=1ms status=200 bytes=2955

so does the console where the websocket server is listening.

The only message is that one from the browser console:

VM1662:37 WebSocket connection to 'wss://notitek.herokuapp.com:8443/' failed: Error in connection establishment: net::ERR_CONNECTION_CLOSED
WrappedWebSocket @ VM1662:37
a._construct @ autobahn.min.js:62
a.Session @ autobahn.min.js:63
a._connect @ autobahn.min.js:78
a.connect @ autobahn.min.js:83
GosSocket.connect @ gos_web_socket_client.js:33
GosSocket @ gos_web_socket_client.js:27
connect @ gos_web_socket_client.js:108
(anonymous) @ (index):13
(index):25 Disconnected for Connection could not be established. with code 3

Any suggestion?

Leggy7 avatar Feb 02 '17 13:02 Leggy7