SpikerSoft.Api/Infrastructure/HealthChecks/MongoDB_HealthCheck.CheckHealthAsync does var client = new MongoClient(_connectionString);on every health-check invocation (the health pipeline polls every ~30s). MongoClient owns a cluster/connection pool with background monitor threads and is explicitly documented to be reused as a singleton — creating one per check slowly leaks pools/threads/sockets for the lifetime of the process.
Same anti-pattern class as #411 / PR #111 (GamePersistenceService). A DI singleton IMongoClient is already registered (SpikerSoft.Api/Extensions/ServiceCollectionExtensions.cs:319).
Fix
Inject the singleton IMongoClient and use it for the ping/settings instead of new MongoClient(...). Bonus: the health check then verifies the app's actual connection pool (more representative) rather than a throwaway one. Keep the config read only for the obfuscated connection-string display in messages.
Acceptance
No new MongoClient in the health-check path; the injected singleton is used.
Existing ObfuscateConnectionString tests still pass; DI can still construct the check (AddCheck<MongoDB_HealthCheck>).
## Problem
`SpikerSoft.Api/Infrastructure/HealthChecks/MongoDB_HealthCheck.CheckHealthAsync` does `var client = new MongoClient(_connectionString);` **on every health-check invocation** (the health pipeline polls every ~30s). `MongoClient` owns a cluster/connection pool with background monitor threads and is explicitly documented to be reused as a singleton — creating one per check slowly leaks pools/threads/sockets for the lifetime of the process.
Same anti-pattern class as #411 / PR #111 (`GamePersistenceService`). A DI singleton `IMongoClient` is already registered (`SpikerSoft.Api/Extensions/ServiceCollectionExtensions.cs:319`).
## Fix
Inject the singleton `IMongoClient` and use it for the ping/settings instead of `new MongoClient(...)`. Bonus: the health check then verifies the **app's actual** connection pool (more representative) rather than a throwaway one. Keep the config read only for the obfuscated connection-string display in messages.
## Acceptance
- No `new MongoClient` in the health-check path; the injected singleton is used.
- Existing `ObfuscateConnectionString` tests still pass; DI can still construct the check (`AddCheck<MongoDB_HealthCheck>`).
Refs #411 (resource-leak availability bombs).
Resolved in spikersoft-backend PR #112 (merged to master). MongoDB_HealthCheck now takes the DI-registered singleton IMongoClient and uses it for the ping/settings instead of new MongoClient(...) per invocation — closing the per-check connection-pool/thread leak. Guarded by MongoDbHealthCheckConstructorTests (2) + the 21 existing obfuscation tests. Closing.
Resolved in spikersoft-backend PR #112 (merged to `master`). `MongoDB_HealthCheck` now takes the DI-registered singleton `IMongoClient` and uses it for the ping/settings instead of `new MongoClient(...)` per invocation — closing the per-check connection-pool/thread leak. Guarded by `MongoDbHealthCheckConstructorTests` (2) + the 21 existing obfuscation tests. Closing.
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
Problem
SpikerSoft.Api/Infrastructure/HealthChecks/MongoDB_HealthCheck.CheckHealthAsyncdoesvar client = new MongoClient(_connectionString);on every health-check invocation (the health pipeline polls every ~30s).MongoClientowns a cluster/connection pool with background monitor threads and is explicitly documented to be reused as a singleton — creating one per check slowly leaks pools/threads/sockets for the lifetime of the process.Same anti-pattern class as #411 / PR #111 (
GamePersistenceService). A DI singletonIMongoClientis already registered (SpikerSoft.Api/Extensions/ServiceCollectionExtensions.cs:319).Fix
Inject the singleton
IMongoClientand use it for the ping/settings instead ofnew MongoClient(...). Bonus: the health check then verifies the app's actual connection pool (more representative) rather than a throwaway one. Keep the config read only for the obfuscated connection-string display in messages.Acceptance
new MongoClientin the health-check path; the injected singleton is used.ObfuscateConnectionStringtests still pass; DI can still construct the check (AddCheck<MongoDB_HealthCheck>).Refs #411 (resource-leak availability bombs).
Resolved in spikersoft-backend PR #112 (merged to
master).MongoDB_HealthChecknow takes the DI-registered singletonIMongoClientand uses it for the ping/settings instead ofnew MongoClient(...)per invocation — closing the per-check connection-pool/thread leak. Guarded byMongoDbHealthCheckConstructorTests(2) + the 21 existing obfuscation tests. Closing.