3

websocket 多实例问题

 2 years ago
source link: https://www.v2ex.com/t/821355
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

V2EX  ›  程序员

websocket 多实例问题

  macscsbf · 1 小时 10 分钟前 · 101 次点击

现在是 k8s 上我开了多个 pod 的服务,每个服务都是一个 websocket 服务端,外部有设备通过 nginx 代理随机选择我的一个 pod 进行连接,我接收连接会请求另一个服务校验, 另一个服务就会查看这个设备之前是否在线,如果在线就往 消息队列里推送踢设备请求,然后我会再建立新的连接。现在问题是设备关机了,但是 socket 连接还未断开,如果设备重启的很快又会创建一个新的连接进来,然后这个连接和之前的连接可能在同一个 pod 上,因为另一个服务会知道这个设备是在线,所以要踢掉旧的连接,但是他是往消息队列里推送,所以另一个服务并不知道到底有没有成功踢除设备, 而这时候我的服务又创建一个新的连接把新的连接踢掉了,这就不知道怎么处理了,目前我就是让服务睡了几秒保证踢掉那个设备。不知道大佬们有什么想法。


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK