zyro23 / grails-spring-websocket

93 stars 28 forks source link

Random 403 error establishing WebSocket handshake #69

Open longwa opened 3 years ago

longwa commented 3 years ago

We are getting a random error sometimes opening a WebSocket connection. When the error occurs, we can usually just restart the pod without any changes and it will work the next time.

The error is:

tf.events-f9669d9aeb6c81c8cfffeaf375400b6e.js:formatted:1127 WebSocket connection to 'wss://dw-dev.test.triu.com/trifleet/stomp/236/2cbqrh2h/websocket' failed: Error during WebSocket handshake: Unexpected response code: 403
SockJS.websocket @ tf.events-f9669d9aeb6c81c8cfffeaf375400b6e.js:formatted:1127
/trifleet/stomp/236/s6d7dvpb/xhr_streaming:1 Failed to load resource: the server responded with a status of 403 ()
/trifleet/stomp/236/ub5z7a3w/xhr:1 Failed to load resource: the server responded with a status of 403 ()
tf.events-f9669d9aeb6c81c8cfffeaf375400b6e.js:formatted:2055 Whoops! Lost connection to undefined

It occurs when we try to create the Stomp client: Stomp.over(new SockJS(stompURL));

At first I thought it was a CORS issue, but I have confirmed that we have CORS enabled and I've set allowed origins to *:

    @Override
    protected void configureStompEndpoints(StompEndpointRegistry registry) {
        registry.addEndpoint("/stomp").setAllowedOrigins("*").withSockJS()
    }

We are using the NGINX Ingress controller for Kubernetes and I have confirmed that it is configured for WebSockets out of the box. We have increased the proxy read/write timeout to ensure they don't timeout.

Like I said, sometimes it works, and sometimes it doesn't. I can't figure out what would cause it to randomly fail with the same configuration.