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

(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

图片转代码服务由CSDN问答提供 功能建议

我目前正在尝试编写一个简单的网络套接字,当有人加入时,该套接字将所有客户端列表列出给每个连接的客户端 或退出websocket连接池。

当前,我正在使用(R)Lock and unlock以确保正在进行并发连接,以避免连接之间的任何干扰。\ n每当我尝试访问连接池时都将其锁定,这包括读取和写入连接池,但是出于某些奇怪的原因,仅当我通过一次发送100个并发连接强行破解Websocket并结束所有连接时,我才收到管道破裂的错误

从外观上看,在删除客户端并广播新的客户端列表之后,便会立即发生错误。

您能找出失败的原因吗? 有人断开连接时将连接池发送给每个客户端? 请记住,只有当我通过创建一个创建100个连接的for循环强行使用websocket连接时,才会发生这种情况;当结束连接列表时,它将失败。

我在失败的地方添加了一条注释


另一点说明是,如果你们有更好的方法发送连接池,则可以遍历整个连接池并将UUID存储到字符串数组中,然后 也可以随时告诉我有关此问题,但现在我主要集中在调试此问题上,因为我想找出失败的地方。

编辑:忘记添加 来源:

Websocket来源: https://gist.github.com / anonymous / eaaf2e5430ed694bc424

压力测试源: 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

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题