Skip to content

Commit

Permalink
🧹 make sure the root asset runtime is closed (#3289)
Browse files Browse the repository at this point in the history
Signed-off-by: Ivan Milchev <[email protected]>
  • Loading branch information
imilchev authored Feb 14, 2024
1 parent 3e13eee commit f9a4c27
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion explorer/scan/discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,29 @@ func DiscoverAssets(ctx context.Context, inv *inventory.Inventory, upstream *ups

resolvedRootAsset = rootAssetWithRuntime.Asset // to ensure we get all the information the connect call gave us

// Make sure the root runtime is closed at the end of the loop if needed. This will close the runtimes for all
// root assets when the entire loop is done. It is NOT running the close after the current iteration of the loop.
// This behaviour is fine for now. If we want to close the runtime after each iteration, we need to revisit
closeRootRuntime := false
defer func() {
if closeRootRuntime {
rootAssetWithRuntime.Runtime.Close()
}
}()

// If the root asset has platform IDs, then it is a scannable asset, so we need to add it
if len(resolvedRootAsset.PlatformIds) > 0 {
prepareAsset(resolvedRootAsset, resolvedRootAsset, runtimeLabels)
if !discoveredAssets.Add(rootAssetWithRuntime.Asset, rootAssetWithRuntime.Runtime) {
rootAssetWithRuntime.Runtime.Close()
closeRootRuntime = true
}
} else {
closeRootRuntime = true
}

// If there is no inventory, no assets have been discovered under the root asset
if rootAssetWithRuntime.Runtime.Provider.Connection.Inventory == nil {
closeRootRuntime = true
continue
}

Expand Down

0 comments on commit f9a4c27

Please sign in to comment.