Skip to content

Send notification to Skeleton on Proxy destruction to "Unsubscribe" method.#358

Open
Tejveerpratap2803 wants to merge 2 commits intoeclipse-score:mainfrom
Tejveerpratap2803:tepr_proxy_method_unsubscribe_notification
Open

Send notification to Skeleton on Proxy destruction to "Unsubscribe" method.#358
Tejveerpratap2803 wants to merge 2 commits intoeclipse-score:mainfrom
Tejveerpratap2803:tepr_proxy_method_unsubscribe_notification

Conversation

@Tejveerpratap2803
Copy link
Copy Markdown
Contributor

@Tejveerpratap2803 Tejveerpratap2803 commented Apr 24, 2026

Notify Skeleton on Proxy destruction to unsubscribe method resources

When a Proxy is destroyed, TeardownMethods() now sends an UnsubscribeServiceMethod IPC message to the Skeleton, which removes the proxy's shared memory region and unregisters all method call handlers for that proxy.

  • Added UnsubscribeServiceMethod IPC path (local + remote) and RegisterOnServiceMethodUnsubscribedHandler to IMessagePassingService
  • Skeleton registers the unsubscription handler in PrepareOffer; on notification, it calls MethodResourceMap::Remove and unregisters all associated method call handlers
  • Added MethodUnsubscriptionRegistrationGuard RAII guard to manage handler lifetime; destroyed in PrepareStopOffer
  • Added SkeletonMethod::OnProxyMethodUnsubscribeFinished to complete the unsubscription flow
  • Refactored registration_guards_ from an ApplicationId-keyed map (with inner vector of guards) to a flat unordered_map<ProxyMethodInstanceIdentifier, pair<pid_t, MethodCallRegistrationGuard>> — one entry per proxy method instance; unsubscribe now erases by the full ProxyMethodInstanceIdentifier, preventing accidental removal of entries from other proxies sharing the same ApplicationId, while crash-detection cleanup still iterates by application_id extracted from the key to correctly remove all stale entries from a crashed process
  • Added unit tests covering all new IPC paths, the unsubscription flow, and the two-proxies-from-the-same-application scenario

@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as draft April 24, 2026 20:08
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 2 times, most recently from 5efbd22 to 11e9903 Compare April 27, 2026 02:34
@Tejveerpratap2803 Tejveerpratap2803 changed the title Send notification to Skeleton on Proxy destruction to "Unsubscribe" m… Send notification to Skeleton on Proxy destruction to "Unsubscribe" method. Apr 27, 2026
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 3 times, most recently from aae5669 to 53393c8 Compare April 28, 2026 18:00
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as ready for review April 28, 2026 18:23
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 5 times, most recently from 30fdce5 to 3abf06f Compare April 28, 2026 21:17
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as draft April 28, 2026 21:18
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 4 times, most recently from 6ca8e82 to a9c92e1 Compare April 28, 2026 21:49
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as ready for review April 28, 2026 21:50
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as draft April 28, 2026 21:50
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 4 times, most recently from caf69c5 to 680061a Compare April 29, 2026 04:50
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as ready for review April 29, 2026 05:29
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch 5 times, most recently from 84ee94a to fa47c66 Compare April 30, 2026 06:03
…ethod

- Add OnProxyMethodUnsubscribeFinished to notify SkeletonMethod when Proxy is destroyed
- Add MethodUnsubscriptionRegistrationGuard for cleanup management
- Add MethodResourceMap for tracking method resource ownership per proxy instance
- Refactor: use ProxyMethodInstanceIdentifier as key in registration_guards_
  (resolves intermediate solution from issue-250236)
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch from fa47c66 to 63f72b5 Compare April 30, 2026 11:26
Copy link
Copy Markdown
Member

@gdadunashvili gdadunashvili left a comment

Choose a reason for hiding this comment

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

For the future reference please split your PRs in thematically meaningful commits to make the review easier.
In the description you outline 6 major bullet points that have been addressed in this PR. Some of this points are sufficiently different that they could have gotten their own commits.

Comment thread score/mw/com/impl/bindings/lola/messaging/i_message_passing_service.h Outdated
Comment thread score/mw/com/impl/bindings/lola/messaging/i_message_passing_service.h Outdated
Comment thread score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/messaging/message_passing_service_instance.h Outdated
Comment thread score/mw/com/impl/bindings/lola/methods/method_resource_map.h Outdated
Comment thread score/mw/com/impl/bindings/lola/methods/method_resource_map_test.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/methods/method_resource_map_test.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/proxy.cpp Outdated
Comment thread score/mw/com/impl/bindings/lola/skeleton.cpp
Comment thread score/mw/com/impl/bindings/lola/skeleton_method.cpp Outdated
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as draft May 6, 2026 09:53
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch from 1fe141b to 383564c Compare May 7, 2026 12:01
@Tejveerpratap2803 Tejveerpratap2803 marked this pull request as ready for review May 7, 2026 12:52
@Tejveerpratap2803 Tejveerpratap2803 force-pushed the tepr_proxy_method_unsubscribe_notification branch from 383564c to 6c96a95 Compare May 7, 2026 14:22
const auto method_shm_path_name = GetMethodChannelShmName();
memory::shared::SharedMemoryFactory::Remove(method_shm_path_name);
method_shm_resource_.reset();
memory::shared::SharedMemoryFactory::RemoveStaleArtefacts(method_shm_path_name);
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.

I don't think this should be called here. It's basically doing the same thing as Remove above except it's intended to be called when the memory region was not created by the process calling it (which is not the case here).


// Subscription state is tracked directly in Proxy (not via ProxyMethod references) because ProxyMethod
// objects may have already been destroyed by the time TeardownMethods() is called from ~Proxy().
const bool is_subscribed = are_proxy_methods_subscribed_.load();
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.

We currently have a race condition between are_proxy_methods_subscribed_ being set and checking it here. It's possible that after a skeleton re-offers, we will call SubscribeServiceMethod and before we set are_proxy_methods_subscribed_ to true, the destructor is called and we check the value here which would still be false.

I think we want to make sure that this function is never called concurrently with the ServiceAvailabilityChangeHandler to avoid any race conditions. So before TeardownMethods is called, we should call find_service_guard_.reset() or better yet, create a guard object which calls the methods cleanup on destruction and ensure that it is destroyed after the find_service_guard_.

}
method_subscription_registration_guard_qm_.emplace(std::move(qm_registration_result).value());

// Register an unsubscription handler for QM proxies. The handler uses the same scope as the subscribe handler
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.

The PrepareOffer function is getting extremely long. Can you please create a new function called RegisterMethodHandlers or something similar? I think it should take a quality type and return a pair of subscribe / unsubscribe handler registration guards. You can then call it for qm and optionally for asil b and store the results in member variables if there are no errors in either (that way you don't have to manually reset the qm guards in case the asil b registration fails).

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