Repository navigation
fix(events): ownership-safe SSE client handles (fixes #483) - #512
Merged
Merged
Conversation
Member
Author
|
@willmmiles I saw we still had a user report in SSE code in this PR: #483 |
mathieucarbou
force-pushed
the
fix/483
branch
2 times, most recently
from
November 13, 2026 12:16
42e87eb to
8744fa3
Compare
AsyncEventSource clients were stored as unique_ptr and exposed to applications only as raw pointers inside callbacks, making it impossible to safely target one connection later (close one session, send to a subset) without use-after-free risk. Rework client lifetime after the design suggested in review of #483: - AsyncEventSourceClient now derives from enable_shared_from_this and the server stores shared_ptr handles; all AsyncTCP callbacks pin the client for the duration of the call so no callback can free the object while its frame is still live. - Client construction/registration moves from the constructor (where shared_from_this() is illegal) to AsyncEventSourceResponse::_respond() via _addClient(); the request is pinned for the connect callbacks. - New app API: onConnectSafe()/onDisconnectSafe() deliver a stable AsyncEventSourceClientPtr handle that may be stored past the callback and used as a connection identifier; onConnectWithRequest() adds the originating request for session association; getClients() returns a safe snapshot. The classic onConnect()/onDisconnect() signatures are unchanged (wrapped into the shared slot, last registered wins). - close() iterates a snapshot instead of the live list (fixes iterator invalidation on synchronous disconnect), ~AsyncEventSource detaches surviving clients, and an app-dropped last handle now closes the underlying connection safely. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
mathieucarbou
force-pushed
the
fix/483
branch
from
November 14, 2026 08:29
8744fa3 to
132259e
Compare
…le form The setters adapt the user's callable directly into the stored form, so it is type-erased once rather than wrapped in a second std::function. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The AsyncClient handle could be deleted by the async thread while a user task is calling through to it. Keeping the object allocated ensures that it is safe to interact with as long as the user is holding a reference to the AsyncEventSourceClient. The AsyncClient itself guarantees ordering across asynchronous operations so this is always safe. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Listed first, another task could close it through getClients() or close(), running the disconnect callback before the connect callback. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Member
Author
|
changes approved! |
willmmiles
approved these changes
Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AsyncEventSource clients were stored as unique_ptr and exposed to applications only as raw pointers inside callbacks, making it impossible to safely target one connection later (close one session, send to a subset) without use-after-free risk.
Rework client lifetime after the design suggested in review of #483:
Changed tested on a hosted build.