Thought this might be handy for others. Knowing regex is useful, kids. Stay in school.
Edit: Turned it into a handy dandy function!
let specificStatusCodeMappings = {
'1000': 'Normal Closure',
'1001': 'Going Away',
'1002': 'Protocol Error',
'1003': 'Unsupported Data',
'1004': '(For future)',
'1005': 'No Status Received',
'1006': 'Abnormal Closure',
'1007': 'Invalid frame payload data',
'1008': 'Policy Violation',
'1009': 'Message too big',
'1010': 'Missing Extension',
'1011': 'Internal Error',
'1012': 'Service Restart',
'1013': 'Try Again Later',
'1014': 'Bad Gateway',
'1015': 'TLS Handshake'
};
function getStatusCodeString(code) {
if (code >= 0 && code <= 999) {
return '(Unused)';
} else if (code >= 1016) {
if (code <= 1999) {
return '(For WebSocket standard)';
} else if (code <= 2999) {
return '(For WebSocket extensions)';
} else if (code <= 3999) {
return '(For libraries and frameworks)';
} else if (code <= 4999) {
return '(For applications)';
}
}
if (typeof(specificStatusCodeMappings[code]) !== 'undefined') {
return specificStatusCodeMappings[code];
}
return '(Unknown)';
}
Usage:
getStatusCodeString(1006); //'Abnormal Closure'
{
'0-999': '(Unused)',
'1016-1999': '(For WebSocket standard)',
'2000-2999': '(For WebSocket extensions)',
'3000-3999': '(For libraries and frameworks)',
'4000-4999': '(For applications)'
}
{
'1000': 'Normal Closure',
'1001': 'Going Away',
'1002': 'Protocol Error',
'1003': 'Unsupported Data',
'1004': '(For future)',
'1005': 'No Status Received',
'1006': 'Abnormal Closure',
'1007': 'Invalid frame payload data',
'1008': 'Policy Violation',
'1009': 'Message too big',
'1010': 'Missing Extension',
'1011': 'Internal Error',
'1012': 'Service Restart',
'1013': 'Try Again Later',
'1014': 'Bad Gateway',
'1015': 'TLS Handshake'
}
Source (with minor edits for terseness): https://developer.mozilla.org/en-US/docs/Web/API/CloseEvent#Status_codes
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and
privacy statement. We’ll occasionally send you account related emails.
Already on GitHub?
Sign in
to your account
Closed
Esqarrouth opened this issue
Feb 27, 2019
· 7 comments
Comments
- I’ve searched for any related issues and avoided creating a duplicate
issue.
Description
I’m logging disconnects in my web game. It seems 75% of the sessions are getting disconnected with the code 1001 (normal) and 25% are getting disconnected with the code 1006 (error). https://tools.ietf.org/html/rfc6455
Sometimes on the error reason I see this text:
CloudFlare WebSocket Proxy restarting
But he majority of 1006 disconnects don’t give any reason at all. The players just disconnect with no reason at all. This usually happens at 5-30 minutes mark while the player is actively playing the game.
The setup I’m has these:
- Node.js
- Express.js
- Cloudflare
- Digital Ocean
- Docker
- https://github.com/websockets/ws
- SSL
- Nginx timeout = 3600s
- Ping/Pong isAlive = 30s
My question is:
- How can I debug this problem better?
- What are common cases which might be causing this problem?
Reproducible in:
- version: 3.3.1
- Node.js version(s): v10.11.0
- OS version(s): Docker 18.09.0
Also posted in: https://stackoverflow.com/questions/54909597/websocket-disconnects-with-1006-error-without-a-reason
- How can I debug this problem better?
There is not much you can do about it because it’s not an issue. It’s a condition you have to deal with.
- What are common cases which might be causing this problem?
A close frame is not received, likely because it was not sent.
Nvm, the 3.x release line should not be affected by that but it doesn’t harm anyway to update, if you can.
Copy link
Contributor
Author
I’m tracking the disconnections used ws 3.3.1 until 3 March then updated ws to 6.1.4. I am adding the charts.
Conclusion:
- Updating to 6.1.4 did not solve the disconnect problems.
- It hasn’t seem to make any changes in terms of general disconnections. (Volume of 1001 could be ignored because it is largely dependent on the traffic that day)
- 1000 errors completely disappeared after updating and 1005 errors started showing up, while previously we didn’t have these. (I hope this is the expected behaviour?)
I hope this is the expected behaviour?
Yes, 1005 is a close frame with an empty payload.
Copy link
Contributor
Author
- How can I debug this problem better?
There is not much you can do about it because it’s not an issue. It’s a condition you have to deal with.
- You mean it is not an issue with ws, right?
- What do you mean there is not much you can do about it?
- What do you mean it’s a condition you have to deal with? If it is common, how do you or other people generally deal with this issue?
- What are common cases which might be causing this problem?
A close frame is not received, likely because it was not sent.
- Do you mean that socket server didn’t send the close frame to client?
- You mean it is not an issue with ws, right?
Yes, I’m not aware of ws dropping close frames.
- What do you mean there is not much you can do about it?
It’s outside of your control. You can’t force the client to send a close frame. If this is coming from a browser try to call ws.close()
before the page unload and see if it makes any difference.
- What do you mean it’s a condition you have to deal with? If it is common, how do you or other people generally deal with this issue?
Treat it for what it is. An «abnormal» closure.
- Do you mean that socket server didn’t send the close frame to client?
The client.
2 participants
Ubuntu 16.04, стек LAMP, для работы с websocket использую библиотеку workerman. Порт открыт в firewall (ufw). Соединение устанавливается корректно, сообщения отправляются, но при попытке чистого закрытия соединения через close как со стороны js так и со стороны сервера соединение у клиента закрывается с ошибкой 1006, без других подробностей. Еще на сервере установлен OpenVpn, но на другом порту. Есть какие-то идеи что это может быть и возможно какие-то шаги для дополнительной отладки чтобы конкретизировать/выяснить причину?
-
Вопрос заданболее трёх лет назад
-
8896 просмотров
Пропустить и перейти к содержимому
Если при подключении к удаленному серверу в расширении remote ssh возникает ошибка:
WebSocket close with status code 1006
или же
Failed to set up socket for dynamic port forward to remote port
Ставим чекбокс в настройках расширения на Remote Server Listen On Socket , он должен быть включен.
Далее при следующей попытке в логе видим:
channel 2: open failed: administratively prohibited: open failed
На удаленном сервере редачим ssh конфиг /etc/ssh/sshd_config
AllowTcpForwarding yes
Параметр должен быть включен.
Не забываем перезапустить ssh очистить каталог .vscode-server и убить повисшие процессы. И пробуем перезапуститься заново.
If you want to annotate a site that’s served over HTTPS then you’ll need to
serve h over HTTPS as well, since the browser will refuse to load external
scripts (eg. H’s bookmarklet) via HTTP on a page served via HTTPS.
To serve your local dev instance of h over HTTPS:
-
Generate a private key and certificate signing request:
openssl req -newkey rsa:1024 -nodes -keyout .tlskey.pem -out .tlscsr.pem
-
Generate a self-signed certificate:
openssl x509 -req -in .tlscsr.pem -signkey .tlskey.pem -out .tlscert.pem
-
Run the dev server with SSL:
-
Since the certificate is self-signed, you will need to instruct your browser to
trust it explicitly by visiting https://localhost:5000 and selecting the option
to bypass the validation error.
Troubleshooting¶
Insecure Response errors in the console¶
The sidebar fails to load and you see net::ERR_INSECURE_RESPONSE
errors in
the console. You need to open https://localhost:5000 and tell the browser to allow
access to the site even though the certificate isn’t known.
Server not found, the connection was reset¶
When you’re serving h over SSL in development making non-SSL requests to h
won’t work.
If you get an error like Server not found or The connection was reset
in your browser (it varies from browser to browser), possibly accompanied by a
gunicorn crash with
AttributeError: 'NoneType' object has no attribute 'uri'
, make sure that
you’re loading https://localhost:5000 in your browser, not http://
.
WebSocket closed abnormally, code: 1006¶
If you see the error message
Error: WebSocket closed abnormally, code: 1006 in your browser,
possibly accompanied by another error message like
Firefox can’t establish a connection to the server at wss://localhost:5001/ws,
this can be because you need to add a security exception to allow your browser
to connect to the websocket. Visit https://localhost:5001 in a browser tab and
add a security exception then try again.
403 response when connecting to WebSocket¶
If your browser is getting a 403 response when trying to connect to the
WebSocket along with error messages like these:
- WebSocket connection to ‘wss://localhost:5001/ws’ failed: Error during WebSocket handshake: Unexpected response code: 403
- Check that your H service is configured to allow WebSocket connections from https://127.0.0.1:5000
- WebSocket closed abnormally, code: 1006
- WebSocket closed abnormally, code: 1001
- Firefox can’t establish a connection to the server at wss://localhost:5001/ws
make sure that you’re opening https://localhost:5000 in your browser and
not https://127.0.0.1:5000.