Fix an issue preventing reloading/upgrading multi-instance applets #13101
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When reloading an applet (i.e after updating the applet) it will fail to restart if there is more than one instance of the applet in the list of applet definitions. The restart fails because of an issue during the initial Cinnamon startup in the initEnabledApplets() function where it calls loadExtension() concurrently for each element in the applet definitions array. The definitions array has multiple entries for applets with multiple instances. This causes duplicated entries in the Extensions.extensions array (which was intended to have only one entry for each spice) because the protection against duplicate entries is executing concurrently, causing most concurrent tasks to see the same empty extensions array resulting in the duplicate check being ineffective.
How does duplicate entries in the extensions array cause the reload to fail: During the reload process we call unloadExtension() where we remove one entry from the extensions array, using forgetExtension(), leaving any duplicates still in the array. When we finish the reload process by calling loadExtension() to restart the Applet, we execute the Extension constructor which calls getExtension() to make sure the extension is not already running. Here it finds one of the duplicate extension array elements and aborts creating a new Applet thinking that the Applet is already running. This is how we fail to restart any of the Applet instances on reload.
This fix avoids the problem by changing initEnabledApplets() so that it will only call loadExtension() once for each unique uuid in the definitions array.