Skip to content

How do I troubleshoot 410 GoneException errors with Amazon API Gateway WebSocket APIs?

3 minute read
0

I want to troubleshoot "410 GoneException" errors when I post a message to my Amazon API Gateway WebSocket API.

Short description

You might receive the "410 GoneException" error for the following reasons:

  • A message was posted to the WebSocket API before the connection was established
  • The connection was terminated or doesn't exist
  • The client disconnected, and then tried to reconnect using the same connectionId
  • The connectionID isn't valid

Note: For WebSocket APIs, the connectionId is required to send a callback response from the backend.

Resolution

To troubleshoot WebSocket API errors, turn on Amazon CloudWatch Logs. For Log level, choose Info to generate execution logs for all requests. Execution logs contain information that you can use to identify and troubleshoot most API errors. For example:

For more information, see CloudWatch log formats for API Gateway.

To establish your connection, use the AWS SDK ApiGatewayManagementApi to call the getConnection operation before you post messages to WebSocket APIs.

Don't make the postToConnection request from the Lambda function integrated with your $connect route. To post a message after the client connection is established, complete the following steps:

  1. Create a child Lambda function that's asynchronously invoked by the parent function.
  2. Initiate a new connection. Then, the $connect route is invoked and the parent function invokes the child function passing the connectionId.
  3. The Lambda child function receives the connectionId and calls the getConnection operation to verify that the connection is valid.
  4. Send a message using the postToConnection method.

Resolve GoneException when $disconnect doesn't invoke

If your $disconnect handler logs show no invocation but you receive a GoneException, then the connection might have closed because of an infrastructure event. To distinguish client-side drops from AWS-side events, review your CloudWatch execution logs and the AWS Health Dashboard. Implement connection validation by calling getConnection before posting messages, and catch the GoneException to remove stale connections from your data store.

For more information, see The $disconnect route.

Related information

Overview of WebSocket APIs in API Gateway

How do I pass a connectionId or custom token to VPC link integration as a header for API Gateway WebSocket APIs?

2 Comments

We have followed all of this guidance, yet occasionally we get a GoneException 401 two minutes after WSS connection and 20 seconds before a following message sent to postToConnection does successfully deliver. There are no disconnections in the meantime shown either in the browser console nor in the OnDisconnectFunction CW log.

It would be helpful if the GoneException had a message property providing an explanation.

replied 3 years ago

Thank you for your comment. We'll review and update the Knowledge Center article as needed

AWS
EXPERT

replied 3 years ago