WebsocketApi does not detect when a client has lost connection

0

I have a problem with my socket server built with webSocketApi. everything works fine unless the decive loose its connectivity, close the conection and someone try to send a message to this device. The websocketApi does not throw any error and if i try to get the connection via @connections API, the SocketApi stll giving like the device is connected untill the idle timeout come. And then it's impossible to detect from my side this case to enqueue the message to be sent later. I'm thinking about using the keep alive client ping to trace the last ping and close the connection manually if the last ping is older than 30 secs or something like this.

Has someone any solution for this case or this is the normal way to works?

thank you.

jsola
asked a year ago281 views
2 Answers
0

@jsola we are using WebSocketApi for one of our Dashboards, and the connection handling is quite seamless.

If you can share your infra code for the WebSocketApi, and the Client code making the connections, I can try to help find the issue you are facing.

answered a year ago
0

Thank you for your reply. In our case, the connection works perfectly unless the client loose the connection, i don't have the code, but is an android service and when the device loose the internet access, it close the connection with the socket(may be the problem is there), but the WebsocketApi does not know that the device has close the connection, then, the connection for the SocketApi still alive but it is false.

From our server side the problem is that from the lambda which try to do the post to the connection the api don't throw any error or if i try to get the connection from that device i receive connection info

static async run(connectionId) {
        const apiGateway = new ApiGatewayManagementApi({
            endpoint: Config.API_DOMAIN,
        })
        
        return await apiGateway
            .getConnection(
                {
                    ConnectionId: connectionId
                }
            )
            .promise();
    }

I receive

{
  ConnectedAt: 2023-02-17T11:11:55.344Z,
  Identity: {
    SourceIp: 'xxx.xxx.xxx.xxx',
    UserAgent: 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'
  },
  LastActiveAt: 2023-02-17T11:11:55.344Z
}

I think the only way to work with this case i make a workaround playing with the idle connections o client pings and disconnect manually if the server don't receive any ping from the client.(I don't like the solution mainly because is not a solution) but i think that with the actual WebsocketApi behavior is the only way Thank you

jsola
answered a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions