pderop commented on PR #606: URL: https://github.com/apache/felix-dev/pull/606#issuecomment-7222478477
Thanks a lot for the careful review and the reproducer, much appreciated! You're right that the early return in `handleAdded` (and in `handleSwapped` for `newEvent`) doesn't close the incoming event. However, I'm not yet sure this can actually leak with the real `ServiceDependencyImpl`. ### Tracker contract As far as I understand the DM tracker, every event for which `addingService` obtained the service also gets a `REMOVED` for the **same event object**: - if the service is tracked when the tracker is closed, `ServiceTracker.close()` sends a `REMOVED` for it; - if it's still being added when the tracker closes, `trackAdding` sees `closed` and sends a `REMOVED` instead of an `ADDED`. `handleRemoved` always closes the event in its `finally` block, even when the dependency entry is gone. So the late `ADDED` ends up on an event that is already closed (or will be). ### Tests I added the following tests in commit [22f4f3f](https://github.com/apache/felix-dev/pull/606/commits/22f4f3f622b7a22c5beb597fbe4a73644be3e3e3) - **`FELIX6886_LateAddedServiceTest`** (unit test, adapted from your reproducer): your reproducer sends a late `ADDED` with no matching `REMOVED`, which the real tracker doesn't seem to do. I've kept your scenario and added one step: like the tracker does for every service it has added, the dependency then sends a `REMOVED` for the same event. This `REMOVED` releases the service even though the dependency has been removed, and the test also checks that handling the late `ADDED` doesn't log any error. - **`FELIX6886_LateServiceEventTest`** (integration test, real Felix framework and real DM tracker), covering the two cases you mentioned: - a late `ADDED`, for a service registered while the instance is being destroyed; - a late `SWAPPED`, for an aspect registered while the instance is being destroyed. In both cases, the late event is handled after the dependency has been removed, and the services are released without the extra `close()`. I may well be missing something here, though. If you think there is a path where the real tracker delivers an `ADDED` (or a `SWAPPED`) without a matching `REMOVED` for the same event, please don't hesitate to come back to me. ### Next step That said, I still need to think about it a bit more: closing the rejected events in those early returns might still be a cheap defensive measure (for example for custom `Dependency` implementations). I'll come back to it. Thanks again! -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
