micko
micko

Reputation: 154

Spring Boot websocket handshake hanging intermittently

Connecting to my web socket end point seems to (randomly) hang more often than not.

Here is the code that registers the endpoint -

@Configuration
@EnableWebSocket
public class WebSocketEndpointConfigurer implements WebSocketConfigurer {

    @Autowired
    private WebSocketConfig webSocketConfig;

    @Autowired
    private WebSocketEndpoint webSocketEndpoint;

    @Override
    public void registerWebSocketHandlers(WebSocketHandlerRegistry registry) {
        registry
            .addHandler(webSocketEndpoint, webSocketConfig.getEndpoint()).setAllowedOrigins("*");
    }
}

And here is my websocket end point -

@Component
public class WebSocketEndpoint extends TextWebSocketHandler {

    private static Logger logger = LoggerFactory.getNoAppLogger(WebSocketEndpoint.class);

    @Override
    public void afterConnectionEstablished(WebSocketSession session) throws Exception {
        logger.info("Websocket connection created");
        //do more things
    }

    @Override
    protected void handleTextMessage(WebSocketSession session, TextMessage message) {
        //do things
    }

    @Override
    public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception {
        //do things
    }
}

I'd say 50% of the time when i try to initiate the connection it is successful. The other 50% of the time it reaches the afterConnectionEstablished() method and I see my log message but it never returns to the browser and Chrome's debug tool says 'pending'.

If I restart my Spring Boot server sometimes it fixes it sometimes it doesn't, it is totally random. Am I missing something here?

Thanks in advance, this is really bugging me.

EDIT: I have tried this with multiple web socket testing clients and have the same results for all.

Upvotes: 1

Views: 1315

Answers (1)

micko
micko

Reputation: 154

Figured it out...

Our corporate anti-virus introduced a bug that affects web sockets....

Upvotes: 1

Related Questions