@@ -261,23 +261,17 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
261
261
},
262
262
})
263
263
}
264
- var shouldStartDiscovery bool
264
+ var shouldRestartDiscovery bool
265
265
{
266
266
// We need to rebuild the PackageManager currently in use by this instance
267
267
// in case this is not the first Init on this instances, that might happen
268
268
// after reinitializing an instance after installing or uninstalling a core.
269
269
// If this is not done the information of the uninstall core is kept in memory,
270
270
// even if it should not.
271
271
272
- exp , release := instance .pm .NewExplorer ()
273
272
// 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 )
281
275
pmb , commitPackageManager := instance .pm .NewBuilder ()
282
276
283
277
loadBuiltinTools := func () []error {
@@ -453,7 +447,7 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
453
447
responseError (s )
454
448
}
455
449
456
- if shouldStartDiscovery {
450
+ if shouldRestartDiscovery {
457
451
pme .DiscoveryManager ().Start ()
458
452
}
459
453
// Refreshes the locale used, this will change the
@@ -464,6 +458,19 @@ func Init(req *rpc.InitRequest, responseCallback func(r *rpc.InitResponse)) erro
464
458
return nil
465
459
}
466
460
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
+
467
474
// Destroy FIXMEDOC
468
475
func Destroy (ctx context.Context , req * rpc.DestroyRequest ) (* rpc.DestroyResponse , error ) {
469
476
if ok := instances .RemoveID (req .GetInstance ().GetId ()); ! ok {
0 commit comments