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 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测