go-socket.io
go-socket.io copied to clipboard
BroadcastToRoom blocks until all messages have been emited, causing delays with slow connections
Describe the bug "broadcast to room" will block broadcasting for a short time
Seems to be related to this: https://github.com/googollee/go-socket.io/blob/master/broadcast.go#L93 Not sure why it's locking even during the .Emit. I assume it only needs to block while actually reading the current list of connections. Been trying to release the lock during Emit, running into other issues in production, so can't say if it works.
To add another data point, I ran into this while trying the simple example of broadcasting to multiple clients when a client has disconnected - it blocks entirely until the read timeout is hit.
It seems to be a fairly easy fix. Not letting the .Emit
call in broadcast.Send
block by using go-routines. This is how the node-implementation works.
https://github.com/googollee/go-socket.io/blob/0c0217c03e1d56780f85e83696203837b62f58ef/broadcast.go#L101
// change
connection.Emit(event, args...)
// to
go connection.Emit(event, args...)
@mrfoe7 what are your thoughts here?
It seems to be a fairly easy fix. Not letting the
.Emit
call inbroadcast.Send
block by using go-routines. This is how the node-implementation works.https://github.com/googollee/go-socket.io/blob/0c0217c03e1d56780f85e83696203837b62f58ef/broadcast.go#L101
// change connection.Emit(event, args...) // to go connection.Emit(event, args...)
@mrfoe7 what are your thoughts here?
Has anyone tried this solution? Is that OK?
We're running this in production for a long time
We're running this in production for a long time
thanks.
Has the problem been solved yet?