ws: External websocket channels fail to send the last queued messages when the server side closes
This has been observed with the VNC viewer of cockpit-machines when the VNC connection is password protected and cockpit-machines fails to provide the correct password.
This is supposed to result in a "Authentication failed" error, but the VNC protocol message with the actual error sometimes doesn't make it all the way to the browser, and we get a "Failed to connect" error instead. Thus, this is mostly cosmetic and also a rarish thing: The password needs to come from qemu.conf and cockpit must be unable to read that file. Otherwise cockpit can find the correct password in the VM config.
The "close" message required by the WebSocket protocol seems to be reliably lost. This results in the Browser correctly reporting a 1006 error code when the socket closes.
That messages are lost in cockpit-ws has been confirmed by instrumenting the web_socket_connection_finalize function to log when it is called with a non-empty "outgoing" queue. For the VNC websocket channel it always has either 1 or 2 unsent messages. If it's 2, then the actual "authentication failed" error message is one of them, and Cockpit will show the wrong "Failed to connect" error.
Source: cockpit-project/cockpit