Skip to content

Conversation

@TienHuyIoT
Copy link

  • Handle client disconnection event properly even if cleanupClients is not called within the main loop.
  • Avoid self-deadlock by using recursive mutex.

- Handle client disconnection event properly even if cleanupClients is not called within the main loop.
- Avoid self-deadlock by using recursive mutex.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (2)

src/AsyncWebSocket.cpp:877

  • Modifications to the _clients vector in _handleDisconnect are not protected by any mutex. Ensure thread safety by protecting access to _clients if concurrent modifications may occur.
void AsyncWebSocket::_handleDisconnect(AsyncWebSocketClient *client) {

src/AsyncWebSocket.cpp:371

  • The manual unlocking of the unique_lock before calling _client->close(true) could be error-prone if future changes introduce exceptions between the unlock and the following code. Consider refactoring the unlock logic into a dedicated scope or helper function to ensure exception safety.
lock.unlock();

@mathieucarbou
Copy link
Member

@TienHuyIoT : if ESPAsyncWS cleans up itself, the current cleanup() method could be emptied (but only keep the signature with an empty body) and we can add a deprecation notice.

@TienHuyIoT
Copy link
Author

if ESPAsyncWS cleans up itself, the current cleanup() method could be emptied (but only keep the signature with an empty body) and we can add a deprecation notice.

The cleanupClients() function has a maxClients argument, so I believe the cleanup() method should be used to handle situations where the number of connected clients exceeds the maxClients limit. However, its usage ultimately depends on the specific requirements of the user’s application.

@mathieucarbou
Copy link
Member

cleanupClients

you are right! I forgot about this part.
thanks!

@mathieucarbou
Copy link
Member

@vortigont @me-no-dev : care to have a look please ?

Copy link
Member

@mathieucarbou mathieucarbou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested, works fine.
Thanks for the improvement!

@mathieucarbou mathieucarbou merged commit e709e5d into ESP32Async:main Apr 10, 2025
30 checks passed
@vortigont
Copy link

looks nice! thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants