dallmann-consulting / OCPP.Core

OCPP server and management UI written in .NET-Core
GNU General Public License v3.0
223 stars 91 forks source link

客户端意外断开连接后,服务器未针对心跳超时关闭websocket连接 #83

Open FuYan opened 4 weeks ago

FuYan commented 4 weeks ago

客户端意外断开连接后,服务器未针对心跳超时关闭websocket连接,导致_chargePointStatusDict 还存储了状态数据,而且此时通过api发送websocket消息会出现异常 private static Dictionary<string, ChargePointStatus> _chargePointStatusDict = new Dictionary<string, ChargePointStatus>();

dallmann-consulting commented 4 weeks ago

I'm not sure what the problem is. Your description is more than short. The OCPP server does not manage the websocket connections. It relies on the ws connection status. If the connection closes the status in the dictionaray is removed. If a connection silently fails there might be a timeout interval until the connection officially gets closed. Of course all API calls will fail here as well. But after both sides have noticed the failure they will close the dead connections and the charger can connect again. Thats the same for every tcp connection.

So where exactly is a problem in the OCPP server?

FuYan commented 4 weeks ago

If the client unexpectedly disconnects and the dictionary is not removed, the management backend will display that the device is online when obtaining the status

dallmann-consulting commented 3 weeks ago

I couldn't really reproduce the issue on one machine. The connection always got closed friendly. Please check the latest changes if that helps.

KETRF commented 3 weeks ago

I have also noticed this issue with NRGkick. When the client unexpectedly disconnects, the management backend still shows the device as online. If the problem occurs again, I will post the logs.

FuYan commented 3 weeks ago

只需要对using (WebSocket webSocket = await context.WebSockets.AcceptWebSocketAsync(subProtocol)) 这里try catch 捕获异常处理就行了, 重现问题很简单, 浏览器连接上ocpp server后 直接在任务管理器结束掉浏览器进程就会出现,多试几次就知道 image