Skip to content

Commit 1721e5d

Browse files
committed
feat(websocket): add log message
1 parent 6cd9aed commit 1721e5d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

api/sockets/handler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const (
3535

3636
// Maximum size of the connection.send channel.
3737
// When the channel is full, the hub closes it (see method hub.run).
38-
connectionChannelSize = 2048
38+
connectionChannelSize = 256
3939
)
4040

4141
type connection struct {

api/sockets/pool.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package sockets
22

3+
import log "github.com/sirupsen/logrus"
4+
35
// hub maintains the set of active connections and broadcasts messages to the
46
// connections.
57
type hub struct {
@@ -47,8 +49,15 @@ func (h *hub) run() {
4749
select {
4850
case conn.send <- m.msg:
4951
default:
52+
53+
log.WithFields(log.Fields{
54+
"context": "websocket",
55+
"user_id": conn.userID,
56+
}).Error("Connection send channel is full, connection closing")
57+
5058
close(conn.send)
5159
delete(h.connections, conn)
60+
_ = conn.ws.Close() // Close the WebSocket connection first
5261
}
5362
}
5463
}

0 commit comments

Comments
 (0)