Websocket closed, reason: Connection was closed abnormally

Our application uses @Push to push data from the server to client - following the Vaadin best practices.

This has been implemented for some time and generally works as intended.

We have had some reports that occasionally the UI is not updating, but we have not been able to replicate or diagnose the issue.

The server is now in a consistent state where push is failing every time - the behavior is 13 failure messages each around 5 second apart before what I assume is a switch to long-polling before the pushed data appears on the UI.

The infrastructure is a Nginx server reverse proxying to the Java server - again this has been in place for some time and works correctly most of the time.

I am aware you can use UI.getCurrent().getPushConfiguration() to tweak the retry attempts / timeout - but what could be causing this?

Anything I can do to diagnose further while the server is in this state?

vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=0' failed: Error during WebSocket handshake: Unexpected response code: 501

console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
vaadinPush-min.js?v=…76c5c4f6c3015b39e:1 WebSocket connection to 'wss://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15b-…json;%20charset=UTF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=8' failed: Error during WebSocket handshake: Unexpected response code: 501
console.js:36 Websocket closed, reason: Connection was closed abnormally (that is, with no close frame being sent). - wasClean: false
VM78:904 
 GET https://redacted/VAADIN/push?v-r=push&v-uiId=1&v-pushId=8f2967f7-f15…TF-8&X-atmo-protocol=true&X-Vaadin-LastSeenServerSyncId=10&_=1737472990038 net::ERR_QUIC_PROTOCOL_ERROR 200 (OK)
1 Like

Response code 501 seems like something related to nginx

Thank you!

A bit of further research into Nginx and Websocket - adding these three lines to the location block in Nginx seems to solve the problem:

    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade"

e.g.

location / {
    proxy_pass http://your_upstream_server;
    proxy_http_version 1.1;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "upgrade";
    proxy_set_header Host $host;
    proxy_set_header X-Real-IP $remote_addr;
    proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
    proxy_set_header X-Forwarded-Proto $scheme;
}
2 Likes

We came today to the similar solution. Our websocket connections were created with a 200 OK response instead of 101 Switching Protocols.
Seems like some browser do have issues when the websocket is created with http2.0, while using http1.1 there is no problem.
Our solution for haproxy:

HaProxy global # Disable H2 Websockets
     h2-workaround-bogus-websocket-clients

backend
     server srv1 yourdomain proto h1 alpn http1.1 ws h1

(based on this article)