dptpn06684 2014-10-07 09:50
浏览 142
已采纳

(websocket)Golang同步数据锁定失败-管道损坏

I'm currently trying to write up a simple websocket which lists all the client lists to each connected client when somebody joins or leaves the websocket connection pool.

Currently I'm using the (R)Lock and unlock to make sure that there is a concurrent connection going on to avoid any interference between the connections. Whenever I try to access the connection pool I lock it, this includes both reading and writing to the pool but for some strange reason ONLY when I bruteforce the websocket by sending 100 concurrent connections at once and I end them all I get a Broken Pipe Error.

From the looks of it the error occurs right after removing the client and broadcasting the new client list.

Could you figure out why it's failing to send the connection pool to each client when somebody looses a connection? Keep in mind that this only happens when I bruteforce the websocket connection by having a for loop which creates 100 connections and when ending the connection list it would fail.

I added a note where it fails.


Another side note is if you guys have a better way to send the connection pool other then by looping through it and storing the UUID into a string array then feel free to tell me about it aswell but right now I'm mainly focusing on debugging this problem as I'd like to figure out where I'm failing.

Edit: Forgot to add source:

Websocket source: https://gist.github.com/anonymous/eaaf2e5430ed694bc424

Stress Test source: https://gist.github.com/anonymous/92ad79ffee1afdfd3382

  • 写回答

1条回答 默认 最新

  • douzuita7325 2014-10-07 10:49
    关注

    So it turns out that the exception only seems to be a problem somehow when catching it in broadcastMessage (Refer to the websocket source).

    As you can see, I catched the error of WriteMessage in the broadcastMessage function. Not entirely sure why it isn't a problem when not catching it but I'll create another question about it.

    Thanks anyway to those who chose to read my the problem I was having!

    For those who are interested, here is the post https://stackoverflow.com/questions/26235760/golang-websocket-broken-pipe-error-only-when-catching-sending-message-to-clien

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突