@@ -261,23 +261,17 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
261261 },
262262 })
263263 }
264- var shouldStartDiscovery bool
264+ var shouldRestartDiscovery bool
265265 {
266266 // We need to rebuild the PackageManager currently in use by this instance
267267 // in case this is not the first Init on this instances, that might happen
268268 // after reinitializing an instance after installing or uninstalling a core.
269269 // If this is not done the information of the uninstall core is kept in memory,
270270 // even if it should not.
271271
272- exp , release := instance .pm .NewExplorer ()
273272 // register whether the discoveries are running, if so we need to start them in
274- // for the previous watchers to keep receiving events
275- if exp .DiscoveryManager () != nil && exp .DiscoveryManager ().DiscoveryRunning () {
276- shouldStartDiscovery = true
277- } else {
278- shouldStartDiscovery = false
279- }
280- release ()
273+ // order for the previous watchers to keep receiving events
274+ shouldRestartDiscovery = areDiscoveriesRunning (instance .pm )
281275 pmb , commitPackageManager := instance .pm .NewBuilder ()
282276
283277 loadBuiltinTools := func () []error {
@@ -453,7 +447,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
453447 responseError (s )
454448 }
455449
456- if shouldStartDiscovery {
450+ if shouldRestartDiscovery {
457451 pme .DiscoveryManager ().Start ()
458452 }
459453 // Refreshes the locale used, this will change the
@@ -464,6 +458,19 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
464458 return nil
465459}
466460
461+ func areDiscoveriesRunning (pm * packagemanager.PackageManager ) bool {
462+ if pm == nil {
463+ return false
464+ }
465+ exp , release := pm .NewExplorer ()
466+ defer release ()
467+
468+ if exp .DiscoveryManager () != nil && exp .DiscoveryManager ().AreDiscoveriesRunning () {
469+ return true
470+ }
471+ return false
472+ }
473+
467474// Destroy FIXMEDOC
468475func Destroy (ctx context.Context , req * rpc.DestroyRequest ) (* rpc.DestroyResponse , error ) {
469476 if ok := instances .RemoveID (req .GetInstance ().GetId ()); ! ok {
0 commit comments