Skip to content

Commit 18b7901

Browse files
Don't cache known-broken compositions (#80021)
Right now we have an issue where users are getting broken MEF compositions cached on their machines, so subsequent launches of the product are operating on a broken composition. It's not "broken" in the sense that "the cache cannot be loaded" but rather the content of the cache is just missing most of our MEF parts. As a defense-in-depth change to deal with potential transient issues, let's not cache compositions we know are bad.
2 parents 13f33ad + 988920f commit 18b7901

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/Workspaces/Remote/Core/ExportProviderBuilder.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,13 @@ private async Task<IExportProviderFactory> GetCompositionConfigurationAsync(Canc
8787
// Assemble the parts into a valid graph.
8888
var config = CompositionConfiguration.Create(catalog);
8989

90-
// Verify we only have expected errors.
91-
92-
ReportCompositionErrors(config, catalog);
93-
94-
// Try to cache the composition.
95-
_ = WriteCompositionCacheAsync(compositionCacheFile, config, cancellationToken).ReportNonFatalErrorAsync();
90+
// Check if we have errors, and report them accordingly.
91+
if (!CheckForAndReportCompositionErrors(config, catalog))
92+
{
93+
// There weren't any errors in the composition, so let's cache it. If there were errors, those errors might have been temporary and we don't want
94+
// to end up in a permanently broken case.
95+
_ = WriteCompositionCacheAsync(compositionCacheFile, config, cancellationToken).ReportNonFatalErrorAsync();
96+
}
9697

9798
// Prepare an ExportProvider factory based on this graph.
9899
return config.CreateExportProviderFactory();
@@ -182,10 +183,14 @@ protected virtual void PerformCacheDirectoryCleanup(DirectoryInfo directoryInfo,
182183

183184
protected abstract bool ContainsUnexpectedErrors(IEnumerable<string> erroredParts);
184185

185-
private void ReportCompositionErrors(CompositionConfiguration configuration, ComposableCatalog catalog)
186+
/// <returns>True if there was an unexpected composition error, false otherwise.</returns>
187+
private bool CheckForAndReportCompositionErrors(CompositionConfiguration configuration, ComposableCatalog catalog)
186188
{
189+
var hasErrors = false;
190+
187191
foreach (var exception in catalog.DiscoveredParts.DiscoveryErrors)
188192
{
193+
hasErrors = true;
189194
LogError($"Encountered exception in the MEF composition: {exception.Message}");
190195
}
191196

@@ -194,6 +199,8 @@ private void ReportCompositionErrors(CompositionConfiguration configuration, Com
194199

195200
if (ContainsUnexpectedErrors(erroredParts))
196201
{
202+
hasErrors = true;
203+
197204
try
198205
{
199206
configuration.ThrowOnErrors();
@@ -204,5 +211,7 @@ private void ReportCompositionErrors(CompositionConfiguration configuration, Com
204211
LogError($"Encountered errors in the MEF composition: {ex.Message}{Environment.NewLine}{ex.ErrorsAsString}");
205212
}
206213
}
214+
215+
return hasErrors;
207216
}
208217
}

0 commit comments

Comments
 (0)