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:
parent
3ad59fb47e
commit
0c1d6ed725
1 changed files with 10 additions and 1 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue