From 790feb844d1d3076afcc7a7dc34590dc974f79c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Dybvik=20Langfors?= Date: Tue, 26 Nov 2024 20:03:28 +0100 Subject: [PATCH] fix: Don't rethrow deserialization exceptions from FusionCache (#1535) ## Description This causes any deserialization exceptions happening when fetching caches to trigger a factory run, instead of bubbling up and hitting the global exception handler. This error was introduced in #1409, which added a non-nullable field to an entity that existed in the distributed cache. ## Related Issue(s) - #1409 ## Verification - [x] **Your** code builds clean without any errors or warnings - [x] Manual testing done (required) - [ ] Relevant automated test added (if you find this hard, leave it and we'll help out) ## Documentation - [ ] Documentation is updated (either in `docs`-directory, Altinnpedia or a separate linked PR in [altinn-studio-docs.](https://github.com/Altinn/altinn-studio-docs), if applicable) --- .../InfrastructureExtensions.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs index bc18a7e63..77ed4665d 100644 --- a/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs +++ b/src/Digdir.Domain.Dialogporten.Infrastructure/InfrastructureExtensions.cs @@ -335,7 +335,12 @@ private static IServiceCollection ConfigureFusionCache(this IServiceCollection s JitterMaxDuration = settings.JitterMaxDuration, EagerRefreshThreshold = settings.EagerRefreshThreshold, - SkipMemoryCache = settings.SkipMemoryCache + SkipMemoryCache = settings.SkipMemoryCache, + + // This will stop deserialization exceptions to be re-thrown, which will cause the factory to run as if + // the cache entry was not found. This avoids crashes which otherwise would happen if entities that + // are cached are changed in a way that makes them incompatible with the cached version. + ReThrowSerializationExceptions = false }) .WithRegisteredSerializer() // If Redis is disabled (eg. in local development or non-web runtimes), we must instruct FusionCache to