Description
When a local bundle uses a remote (imported) service using ZooKeeper discovery, and the local bundle is restarted, the imported service may no longer be available (until the remote service bundle is also restarted).
This may occur inconsistently due to a race condition - I've managed to recreate it in a debugger such that whenever I stop at some breakpoint in TopologyManagerImport for a few seconds the service is re-imported properly, but when I let it run without stalling at a breakpoint it is never imported after the bundle restart.
After much investigation the root cause was found to be in the ZooKeeper discovery's InterfaceMonitorManager, which does not properly notify modified EndpointListeners of pre-discovered endpoints. When the client bundle is restarted, the TopologyManagerImport (which is an EndpointListener) service properties are modified to reflect the changing interest scope (reduce followed by expand of requested remote service), but due to said bug it will not receive a notification about the previously-known remote service endpoint. Since the TMI's actual un-export/re-import is done in a separate thread, there is a race condition of whether or not the endpoint will be known at the time of import, and thus it will sometimes not be re-imported.