eclipse / paho.mqtt.javascript

paho.mqtt.javascript
Other
1.14k stars 468 forks source link

Connection closed before receiving a handshake response #154

Open pokal4u opened 6 years ago

pokal4u commented 6 years ago

Hi, We are getting below error in some browsers(chrome or mozilla) when we connect mqtt using web sockets. When we clear browser history then connected. Error: WebSocket connection to 'wss://host:port/mqtt' failed: Connection closed before receiving a handshake response Paho.MQTT.ClientImpl._doConnect @ mqttws31.js:979

My connection:

var client = new Paho.MQTT.Client("host", Number(port), "myClientId" + new Date().getTime()); client.connect({userName:username,password:password,onSuccess:onConnect,onFailure:doFail,useSSL:true,cleanSession:false});

So please look into this. Thanks

pokal4u commented 6 years ago

any one please look into this

DayTimeDreamer commented 6 years ago

Maybe you don't boot the broker properly. Which broker do you use? Or you can try set useSSL=false.

pokal4u commented 6 years ago

broker: mosquitto. Our site running on https, so useSSL should be true. If set false getingt error. And mqtt connected for some users(in all browsers) without clearing browser cache.

Please check attache files of chrome versions and response code of different systems, one system got error and another one connected succesfully.

Mosquitto configuration:

Plain WebSockets configuration listener port protocol websockets

WebSockets over TLS/SSL listener port protocol websockets cafile ca.crt certfile cer.crt keyfile key

mqtt_connet mqtt_connet1 mqtt_disconnect mqtt_disconnect1

jpwsutton commented 6 years ago

This looks like it could be an HTTPS issue, does this only happen with Secure websockets connection, or with plain connections as well?

pokal4u commented 6 years ago

for plain connection also getting same error in same browser, but why this relation with browser cache? when I clear cache then connected

jpwsutton commented 6 years ago

Can you try this against the server at iot.eclipse.org and confirm if you see the same problems connecting to that please?

pokal4u commented 6 years ago

using this "iot.eclipse.org" connected in all browsers. Please suggest me where I did wrong. I will share more info if required.

jpwsutton commented 6 years ago

Looks like it might be a configuration issue with your instance of Mosquitto, I'd suggest checking the Mosquitto logs to see if there is anything in that might explain the connection loss.

pokal4u commented 6 years ago

Where can I enable logs and any default location for saved logs?

pokal4u commented 6 years ago

in logs getting this error "Ran out of header data space"

luiscolmenares commented 5 years ago

Hi @pokal4u were you able to resolve this? I am having the same issue!

l0stmyself commented 5 years ago

Hi. Me too

jabedhasan21 commented 5 years ago

for plain connection also getting same error in same browser, but why this relation with browser cache? when I clear cache then connected

It's connected perfectly when I clear browser cache

zcmack commented 5 years ago

tagging onto this as well. when i connect in an incognito window, no issues. but from my normal session i am not completing the handshake.

jayanthiNNaik commented 4 years ago

have you solved this issue? I am having the same issue! Please someone help me@pokal4u

kumar1008k commented 4 years ago

yes im facing same problem ,when i connect in an incognito window, no issues. but from my normal session i am not completing the handshake. can you suggest how to solve this problem. @luiscolmenares, @DayTimeDreamer, @pokal4u.

scovic commented 4 years ago

Anyone resolved this? Any solution?

u236 commented 4 years ago

Have some problem! Is there any solution?

argupta23 commented 4 years ago

One way to debug the issue would be to add the below line into your /etc/mosquitto/mosquitto.conf websockets_log_level 255 and restart the mosquitto process.

You can then tail the generated log file and see what is filling up the header.

Hope that helps.

syntithenai commented 4 years ago

I also have this problem.

Related to

In browser console I see Connection closed before receiving a handshake response when trying to connect. Cognito mode or clear cache both allow the connection to work.

Tried websockets_log_level 255 and I am also seeing "Ran out of header data space" in the logs. (logs included below) I can see a bunch of WSI_TOK logs which include recognisable sequences for language and cookie It looks like the cookie data is the last thing in the logs before "Ran out of header data space"

If I use the browser settings to block cookies for the site, the mqtt connection works but other features like login break.

https://github.com/eclipse/mosquitto/issues/208 suggests using websockets_headers_size 4096 in mosquitto.conf (issue suggests max_http_header_data but mosquitto_conf reference says websockets_headers_size) works for versions >= 1.6 of mosquitto (which probably means build mosquitto from source) This works for me.

Another approach is ensuring that the web server does not set the cookies. In my case Flask is setting a session cookie. I haven't tried this option but suspect that might work too.

cheers Steve

============================================== 1585821012: known hdr 22 1585821012: WSITOK(22) ' ' 1585821012: WSITOK(22) 'e' 1585821012: WSITOK(22) 'n' 1585821012: WSITOK(22) '-' 1585821012: WSITOK(22) 'U' 1585821012: WSITOK(22) 'S' 1585821012: WSITOK(22) ',' 1585821012: WSITOK(22) 'e' 1585821012: WSITOK(22) 'n' 1585821012: WSITOK(22) ';' ...................................... 1585821012: WSITOK(22) '6' '585821012: WSITOK(22) ' 1585821012: * 1585821012: WSI_TOKEN_SKIPPING_SAW_CR ' ' 1585821012: WSI_TOKEN_NAME_PART 'C' (mode=0) 1585821012: WSI_TOKEN_NAME_PART 'o' (mode=0) 1585821012: WSI_TOKEN_NAME_PART 'o' (mode=0) 1585821012: WSI_TOKEN_NAME_PART 'k' (mode=0) 1585821012: WSI_TOKEN_NAME_PART 'i' (mode=0) 1585821012: WSI_TOKEN_NAME_PART 'e' (mode=0) 1585821012: WSI_TOKEN_NAME_PART ':' (mode=0) 1585821012: known hdr 26 1585821012: WSITOK(26) ' ' 1585821012: WSITOK(26) 's' 1585821012: WSITOK(26) 'e' 1585821012: WSITOK(26) 's' 1585821012: WSITOK(26) 's' 1585821012: WSITOK(26) 'i' 1585821012: WSITOK(26) 'o' 1585821012: WSITOK(26) 'n' 1585821012: WSITOK(26) '=' 1585821012: WSITOK(26) '.' 1585821012: WSITOK(26) 'e' 1585821012: WSITOK(26) 'J' 1585821012: WSITOK(26) 'y' 1585821012: WSITOK(26) '9' ............................................................................................................................... 1585821012: WSITOK(26) 's' 1585821012: WSITOK(26) 'z' 1585821012: WSITOK(26) 'I' 1585821012: WSITOK(26) 'v' 1585821012: Ran out of header data space 1585821012: lws_parse failed 1585821012: lws_header_table_detach: wsi 0x564413a70440: ah 0x564413a56e70 (tsi=0, count = 1) 1585821012: closing connection at lws_read bail: 1585821012: lws_close_free_wsi: shutting down connection: 0x564413a70440 (sock 12, state 2)

snoopyCode commented 4 years ago

I had the same issue. Interestingly only with Chrome. MQTT Box and Safari work well. It's not a real fix but replacing the DNS name with the IP of the mqtt mosquitto host worked for me. Still looking for the real problem. Does not seem to be a paho mqtt issue.

mortenmoulder commented 3 years ago

@snoopyCode Thank you so much for suggesting that. Been struggling trying to fix this annoying issue, and it turns out my host needed to be an IP and not a hostname.