mirror of
https://github.com/FrankerFaceZ/FrankerFaceZ.git
synced 2025-08-04 11:44:00 +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.
|
// 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"}
|
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
|
// CloseFirstMessageNotHello is the termination reason
|
||||||
var CloseFirstMessageNotHello = websocket.CloseError{
|
var CloseFirstMessageNotHello = websocket.CloseError{
|
||||||
Text: "Error - the first message sent must be a 'hello'",
|
Text: "Error - the first message sent must be a 'hello'",
|
||||||
Code: websocket.ClosePolicyViolation,
|
Code: websocket.ClosePolicyViolation,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const sendMessageBufferLength = 125
|
||||||
|
const sendMessageAbortLength = 50
|
||||||
|
|
||||||
// RunSocketConnection contains the main run loop of a websocket connection.
|
// RunSocketConnection contains the main run loop of a websocket connection.
|
||||||
|
|
||||||
// First, it sets up the channels, the ClientInfo object, and the pong frame handler.
|
// 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()
|
defer closer()
|
||||||
|
|
||||||
_clientChan := make(chan ClientMessage)
|
_clientChan := make(chan ClientMessage)
|
||||||
_serverMessageChan := make(chan ClientMessage)
|
_serverMessageChan := make(chan ClientMessage, sendMessageBufferLength)
|
||||||
_errorChan := make(chan error)
|
_errorChan := make(chan error)
|
||||||
stoppedChan := make(chan struct{})
|
stoppedChan := make(chan struct{})
|
||||||
|
|
||||||
|
@ -272,6 +278,9 @@ RunLoop:
|
||||||
DispatchC2SCommand(conn, &client, msg)
|
DispatchC2SCommand(conn, &client, msg)
|
||||||
|
|
||||||
case msg := <-serverMessageChan:
|
case msg := <-serverMessageChan:
|
||||||
|
if len(serverMessageChan) > sendMessageAbortLength {
|
||||||
|
CloseConnection(conn, &CloseTooManyBufferedMessages)
|
||||||
|
}
|
||||||
SendMessage(conn, msg)
|
SendMessage(conn, msg)
|
||||||
|
|
||||||
case <-time.After(1 * time.Minute):
|
case <-time.After(1 * time.Minute):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue