Feature Request: Add setMaxClients() to limit concurrent HTTP connections #366
Replies: 1 comment
-
|
Hi @VladimirVecera , please open a discussion next time. This is not an issue. also, please have a look at the examples… there is a way to limit concurrent connections and there is even an example. you can even adapt it to go further and use a middleware with a semaphore. the thing that nobody can control though is to have a limitation at the network level. When a connection is requested, the async tcp stack allocates a client and then pass it to the server for request parsing and handling. This is when a middleware can be used to close the request. So there is nothing to limit the number of concurrent connections but there is a mechanism to limit the number of concurrent requests (1 connection == 1 request). So based on this knowledge you can tweak the semaphore count. if you need yo go deeper and control the compilation flags at network level / Lwip you might want to use esp idf. FYI AsyncWebSocket cleanupClients() does not prevent a concurrent connections to be made: it is just a way to cleanup closed clients of not yet cleaned up and also a way to close old ones if too many. You can look at the source code to know what it does exactly. Also your error (Stack canary watchpoint) ia more related to the fact that your callback are executing too slowly and are blocking the async_tcp task from processing network packets. This async. You must not in any case block in a handler . Your code must be as fast as possible because the callback are executing within the context of the async _tcp task and you need to return as fast as possible so that the task can continue processing next packet. So you might want to fix your application code first. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Platform
ESP32
IDE / Tooling
Arduino (IDE/CLI)
What happened?
Feature Request: There is no way to limit concurrent HTTP connections.
On memory-constrained projects, rapid page navigation causes stack overflow
because too many connections are handled simultaneously.
I would like to request adding setMaxClients() method to AsyncWebServer class,
similar to how AsyncWebSocket has cleanupClients().
Stack Trace
Example crash when rapidly clicking through pages with CONFIG_ASYNC_TCP_STACK_SIZE=3200:
Guru Meditation Error: Core 0 panic'ed (Unhandled debug exception)
Debug exception reason: Stack canary watchpoint triggered (async_tcp)
Note: This is not a bug report - including stack trace only because field is required.
The crash is preventable by increasing stack size, but limiting max clients
would provide better memory control.
Minimal Reproductible Example (MRE)
...
I confirm that:
Beta Was this translation helpful? Give feedback.
All reactions