Hello everyone,
I'm currently experiencing a perplexing issue with AWS API Gateway's WebSocket service where the WebSocket connection gets disconnected by the API Gateway, but the expected OnClosed event does not trigger on the client-side, with the same logic on the client but connecting to my node.js WebSocket server on my local machine the OnClosed event does trigger, so why isn't it triggering when disconnected from the API Gateway?
I'm hoping to find some insights or solutions from anyone who might have faced a similar issue or has expertise with WebSockets and AWS API Gateway.
--Issue Description--
I've set up a WebSocket API using AWS API Gateway to facilitate real-time communication between my client application and server. The WebSocket connection is established without any issues, and both message sending and receiving work as expected with the appropriate client events being triggered for OnConnected, OnMessageReceived etc. However, when the API Gateway closes the WebSocket connection (e.g., due to the 2-hour connection limit, 10 minute timeout or manual disconnection from the server side), my client application does not seem to detect this disconnection through the standard OnClosed WebSocket event.
--Expected Behavior--
Upon disconnection initiated by AWS API Gateway (either due to timeout or server-side action), I expect the client's WebSocket OnClosed event to be executed, allowing my client application to handle the disconnection gracefully (e.g., by pooling messages that need to be sent and attempting reconnection or alerting my management service).
--Actual Behavior--
The WebSocket connection is terminated by the API Gateway, but the client-side OnClosed event handler does not get executed. There are no errors or exceptions thrown on the client side; it's as if the disconnection goes unnoticed by the client WebSocket implementation.
--Notes--
I have also tried connecting to the API Gateway via a client WebSocket node.js app and that application has the same results by also not executing the OnClosed event.
I also read that someone else using API Gateway WebSocket but with a different issue API Gateway sends a status code "1001 - Going away" when they timeout or disconnect.
I'm at a loss for why the OnClosed event isn't being triggered upon disconnection by the API Gateway. If anyone has insights, suggestions, or solutions based on your experiences, I would greatly appreciate your input.
Thank you in advance for your help!