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
已提问 1 年前289 查看次数
2 回答
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.

已回答 1 年前
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
已回答 1 年前

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则

相关内容