Skip to content

Replace SubscriptionData value map with shared_ptr; drop stale notifi…#105

Open
swethasukumarr wants to merge 3 commits into
developfrom
feature/raceFix
Open

Replace SubscriptionData value map with shared_ptr; drop stale notifi…#105
swethasukumarr wants to merge 3 commits into
developfrom
feature/raceFix

Conversation

@swethasukumarr

Copy link
Copy Markdown
Contributor

…cations via weak_ptr

Copilot AI review requested due to automatic review settings July 17, 2026 18:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens the C++ helper subscription path against a use-after-free race (MONUI-908) where in-flight notifications could invoke callbacks after SubscriptionData was destroyed.

Changes:

  • Store SubscriptionData as std::shared_ptr and guard event callbacks with a std::weak_ptr to safely drop stale notifications after unsubscribe.
  • Add regression unit tests covering notification delivery while subscribed and dropping after unsubscribeAll() / unsubscribe(id).
  • Add exception handling in the gateway notification worker to prevent termination on callback exceptions (including std::bad_any_cast).

Reviewed changes

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

File Description
src/helpers_impl.h Switches subscription storage to shared_ptr and wraps gateway callbacks with a weak_ptr guard to avoid use-after-free.
src/gateway.cpp Wraps notification callback dispatch in try/catch to log and continue on exceptions during notification delivery.
test/unit/helperTest.cpp Adds regression tests to validate that stale notifications are dropped without crashing and that active subscriptions still receive notifications.

Comment thread src/gateway.cpp
Comment thread test/unit/helperTest.cpp
Copilot AI review requested due to automatic review settings July 17, 2026 18:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/helpers_impl.h
Comment thread src/gateway.cpp
Copilot AI review requested due to automatic review settings July 17, 2026 18:41

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Copilot AI review requested due to automatic review settings July 17, 2026 18:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread src/helpers_impl.h Outdated
Comment thread src/gateway.cpp
Comment thread src/helpers_impl.h Fixed
Comment thread test/unit/helperTest.cpp Fixed
Comment thread test/unit/helperTest.cpp Fixed
Comment thread test/unit/helperTest.cpp Fixed
Copilot AI review requested due to automatic review settings July 17, 2026 19:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.

Comment thread src/helpers_impl.h Outdated
Comment thread src/helpers_impl.h Outdated
Comment thread src/helpers_impl.h Outdated
Comment thread src/helpers_impl.h Outdated
Comment thread test/unit/gatewayTest.cpp
Copilot AI review requested due to automatic review settings July 17, 2026 20:03

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

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

Comment thread test/unit/helperTest.cpp
ASSERT_TRUE(subResult);
ASSERT_TRUE(capturedCallback) << "wrappedCallback must have been captured";

// Worker thread dispatches notification while subscription is still alive
Comment thread test/unit/helperTest.cpp
Comment on lines +691 to +693
// Platform sends onSpeechInterrupted — notification was already queued in-flight
// Replay the race: call the wrappedCallback with the now-stale usercb address.
ASSERT_TRUE(capturedCallback) << "wrappedCallback must have been captured";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants