From 9063f9d732664e69730cb7275119c7f535525998 Mon Sep 17 00:00:00 2001 From: Ehsan Mohandesi Date: Sun, 13 Sep 2026 22:16:18 -0500 Subject: [PATCH] Give the public data import job its own HttpClient StartImportFromPublicDataRepo captured the injected, request-scoped HttpClient inside the queued work item. The request completes long before the background job runs, so the client was already disposed and the import died immediately with ObjectDisposedException. Let the job own a client for its lifetime. --- .../GanjoorService-PublicDataImport.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PublicDataImport.cs b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PublicDataImport.cs index b1ec2ee0..40adfb68 100644 --- a/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PublicDataImport.cs +++ b/RMuseum/Services/Implementation/GanjoorService-Partials/GanjoorService-PublicDataImport.cs @@ -8,6 +8,7 @@ using RSecurityBackend.Services.Implementation; using System; using System.Collections.Generic; using System.Linq; +using System.Net.Http; using System.Text.Json; using System.Threading.Tasks; @@ -55,6 +56,9 @@ namespace RMuseum.Services.Implementation ( async token => { + // the injected _httpClient is request-scoped and already disposed by the + // time this queued work item runs, so the job owns its own client + using HttpClient importHttpClient = new HttpClient() { Timeout = TimeSpan.FromMinutes(5) }; using (RMuseumDbContext context = new RMuseumDbContext(new DbContextOptions())) { LongRunningJobProgressServiceEF jobProgressServiceEF = new LongRunningJobProgressServiceEF(context); @@ -63,7 +67,7 @@ namespace RMuseum.Services.Implementation try { IPublicDataSource source = useHttp - ? new HttpPublicDataSource(_httpClient, location) + ? new HttpPublicDataSource(importHttpClient, location) : new LocalFileSystemPublicDataSource(location); string manifestJson = await source.ReadTextAsync("manifest.json");