1
0
Fork 0
mirror of https://github.com/FrankerFaceZ/FrankerFaceZ.git synced 2025-08-03 00:18:31 +00:00

Protect against filled send buffers

This commit is contained in:
Kane York 2015-11-17 00:28:42 -08:00
parent 3ad59fb47e
commit 0c1d6ed725

View file

@ -150,12 +150,18 @@ var CloseGotBinaryMessage = websocket.CloseError{Code: websocket.CloseUnsupporte
// CloseTimedOut is the termination reason when the client fails to send or respond to ping frames.
var CloseTimedOut = websocket.CloseError{Code: websocket.CloseNoStatusReceived, Text: "no ping replies for 5 minutes"}
// CloseTooManyBufferedMessages is the termination reason when the sending thread buffers too many messages.
var CloseTooManyBufferedMessages = websocket.CloseError{Code: websocket.CloseMessageTooBig, Text: "too many pending messages"}
// CloseFirstMessageNotHello is the termination reason
var CloseFirstMessageNotHello = websocket.CloseError{
Text: "Error - the first message sent must be a 'hello'",
Code: websocket.ClosePolicyViolation,
}
const sendMessageBufferLength = 125
const sendMessageAbortLength = 50
// RunSocketConnection contains the main run loop of a websocket connection.
// First, it sets up the channels, the ClientInfo object, and the pong frame handler.
@ -185,7 +191,7 @@ func RunSocketConnection(conn *websocket.Conn) {
defer closer()
_clientChan := make(chan ClientMessage)
_serverMessageChan := make(chan ClientMessage)
_serverMessageChan := make(chan ClientMessage, sendMessageBufferLength)
_errorChan := make(chan error)
stoppedChan := make(chan struct{})
@ -272,6 +278,9 @@ RunLoop:
DispatchC2SCommand(conn, &client, msg)
case msg := <-serverMessageChan:
if len(serverMessageChan) > sendMessageAbortLength {
CloseConnection(conn, &CloseTooManyBufferedMessages)
}
SendMessage(conn, msg)
case <-time.After(1 * time.Minute):