Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit bed4146

Browse files
committed
add limit to how many messages can be queued for each web socket client
1 parent 4c621f3 commit bed4146

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

src/AsyncWebSocket.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,12 @@ void AsyncWebSocketClient::_queueMessage(AsyncWebSocketMessage *dataMessage){
551551
delete dataMessage;
552552
return;
553553
}
554-
_messageQueue.add(dataMessage);
554+
if(_messageQueue.length() > WS_MAX_QUEUED_MESSAGES){
555+
ets_printf("ERROR: Too many messages queued\n");
556+
delete dataMessage;
557+
} else {
558+
_messageQueue.add(dataMessage);
559+
}
555560
if(_client->canSend())
556561
_runQueue();
557562
}

src/AsyncWebSocket.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@
2424
#include <Arduino.h>
2525
#ifdef ESP32
2626
#include <AsyncTCP.h>
27+
#define WS_MAX_QUEUED_MESSAGES 32
2728
#else
2829
#include <ESPAsyncTCP.h>
30+
#define WS_MAX_QUEUED_MESSAGES 8
2931
#endif
3032
#include <ESPAsyncWebServer.h>
3133

0 commit comments

Comments
 (0)