Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] Crash after client disconnect from Server-Sent-Events #28

Closed
gsicilia82 opened this issue Jan 28, 2025 · 1 comment · Fixed by #29
Closed

[BUG] Crash after client disconnect from Server-Sent-Events #28

gsicilia82 opened this issue Jan 28, 2025 · 1 comment · Fixed by #29
Assignees
Labels
Type: Bug Something isn't working

Comments

@gsicilia82
Copy link

Hello and thank you for your great work. Because I found also the solution for the bug, hopefully this short description is enough:
I wanted to switch from Websockets to SSE. However, I encountered an issue in release v3.6.2: If I disconnect a client, the esp32s3 crashs in this function:

void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient *client) {
  if (_disconnectcb) {
    _disconnectcb(client);
  }
#ifdef ESP32
  std::lock_guard<std::mutex> lock(_client_queue_lock);
#endif
  for (auto i = _clients.begin(); i != _clients.end(); ++i) {
    if (i->get() == client) {
      _clients.erase(i);
    }
  }
  _adjust_inflight_window();
}

Issue and simple fix:
By erasing an element from _clients the iterator becomes "unusable". Therefore it is necessary to break the loop after erase:

void AsyncEventSource::_handleDisconnect(AsyncEventSourceClient *client) {
  if (_disconnectcb) {
    _disconnectcb(client);
  }
#ifdef ESP32
  std::lock_guard<std::mutex> lock(_client_queue_lock);
#endif
  for (auto i = _clients.begin(); i != _clients.end(); ++i) {
    if (i->get() == client) {
      _clients.erase(i);
     break;
    }
  }
  _adjust_inflight_window();
}
@mathieucarbou
Copy link
Member

thanks! will open a fix pr later.

@vortigont : FYI ;-)

@mathieucarbou mathieucarbou self-assigned this Jan 28, 2025
@mathieucarbou mathieucarbou added Type: Bug Something isn't working and removed Status: Awaiting triage labels Jan 28, 2025
vortigont added a commit that referenced this issue Jan 28, 2025
fix(sse): break loop after erasing client
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants