fix(dp): keep X509Certificate2 alive for DataProtection key ring

- Remove `using var` from dpCert so the cert stays alive for
  ProtectKeysWithCertificate (was disposed, causing
  CryptographicException)
- Add query filter on DiscoveredStreamUrl for model warning #10622
- Simplify migration retry: call Migrate() directly instead of
  GetPendingMigrations()+Migrate() to reduce transient startup noise
This commit is contained in:
Arnaud Dartois committed 2026-07-20 19:58:32 +00:00
1 parent 947414cc3f
commit 34037c20bf
3 files changed
+18 -20

No files matched your search

+16 -19
View File
@@ -277,31 +277,28 @@ using (var scope = app.Services.CreateScope())
var retryDelay = TimeSpan.FromSeconds(2);
for (var attempt = 1; attempt <= maxRetries; attempt++)
{
try
{
if (db.Database.GetPendingMigrations().Any())
try
{
logger.LogInformation("Applying pending database migrations (attempt {Attempt}/{MaxRetries})...", attempt, maxRetries);
logger.LogInformation("Applying database migrations (attempt {Attempt}/{MaxRetries})...", attempt, maxRetries);
db.Database.Migrate();
logger.LogInformation("Database migrations applied successfully");
break;
}
catch (Exception ex) when (attempt < maxRetries)
{
logger.LogWarning(ex,
"Database migration attempt {Attempt}/{MaxRetries} failed. Retrying in {Delay}s...",
attempt, maxRetries, retryDelay.TotalSeconds);
await Task.Delay(retryDelay);
retryDelay = TimeSpan.FromSeconds(retryDelay.TotalSeconds * 2);
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to apply database migrations after {MaxRetries} attempts.", maxRetries);
throw;
}
break;
}
catch (Exception ex) when (attempt < maxRetries)
{
logger.LogWarning(ex,
"Database migration attempt {Attempt}/{MaxRetries} failed. Retrying in {Delay}s...",
attempt, maxRetries, retryDelay.TotalSeconds);
await Task.Delay(retryDelay);
retryDelay = TimeSpan.FromSeconds(retryDelay.TotalSeconds * 2);
}
catch (Exception ex)
{
logger.LogCritical(ex, "Failed to apply database migrations after {MaxRetries} attempts.", maxRetries);
throw;
}
}
}
// ── Register recurring Hangfire jobs ─────────────────────────────────