SpikerSoft.Business/Services/KeycloakAdminService.cs is a primary-constructor class that already injects HttpClient httpClient, and every method uses it with a per-request HttpRequestMessage carrying the Authorization header (e.g. GetAdminTokenAsync, AssignRealmRoleAsync, the availability checks — all httpClient.SendAsync(...)).
GetRoleMembersAsync (line ~444) is the lone outlier:
This news + disposes an HttpClient on every call (socket/TIME_WAIT leak, same family as #411/#433/#434) and mutates DefaultRequestHeaders — the anti-pattern the rest of the class deliberately avoids.
Fix
Use the injected httpClient with a per-request HttpRequestMessage + Authorization header, matching every sibling method. No ctor change; URL construction unchanged.
Acceptance
No new HttpClient() in KeycloakAdminService; GetRoleMembersAsync uses the injected client.
Returns the same role members (unit-testable via the existing Mock<HttpMessageHandler> harness — the stub sits on the injected client, so the test only passes once the injected client is used).
## Problem
`SpikerSoft.Business/Services/KeycloakAdminService.cs` is a primary-constructor class that **already injects `HttpClient httpClient`**, and every method uses it with a per-request `HttpRequestMessage` carrying the `Authorization` header (e.g. `GetAdminTokenAsync`, `AssignRealmRoleAsync`, the availability checks — all `httpClient.SendAsync(...)`).
`GetRoleMembersAsync` (line ~444) is the lone outlier:
```csharp
using var client = new HttpClient();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", token);
```
This news + disposes an `HttpClient` on every call (socket/`TIME_WAIT` leak, same family as #411/#433/#434) and mutates `DefaultRequestHeaders` — the anti-pattern the rest of the class deliberately avoids.
## Fix
Use the injected `httpClient` with a per-request `HttpRequestMessage` + `Authorization` header, matching every sibling method. No ctor change; URL construction unchanged.
## Acceptance
- No `new HttpClient()` in `KeycloakAdminService`; `GetRoleMembersAsync` uses the injected client.
- Returns the same role members (unit-testable via the existing `Mock<HttpMessageHandler>` harness — the stub sits on the injected client, so the test only passes once the injected client is used).
Refs #411 (resource-leak availability bombs).
Resolved in spikersoft-backend PR #114 (merged to master). GetRoleMembersAsync now uses the injected HttpClient with a per-request Authorization header, matching every sibling method — no more per-call new HttpClient(). Guarded by KeycloakAdminServiceRoleMembersTests (stub on the injected client) + 21 existing Keycloak tests. This cleared the last non-benign new HttpClient() in the backend. Closing.
Resolved in spikersoft-backend PR #114 (merged to `master`). `GetRoleMembersAsync` now uses the injected `HttpClient` with a per-request `Authorization` header, matching every sibling method — no more per-call `new HttpClient()`. Guarded by `KeycloakAdminServiceRoleMembersTests` (stub on the injected client) + 21 existing Keycloak tests. This cleared the last non-benign `new HttpClient()` in the backend. 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.Business/Services/KeycloakAdminService.csis a primary-constructor class that already injectsHttpClient httpClient, and every method uses it with a per-requestHttpRequestMessagecarrying theAuthorizationheader (e.g.GetAdminTokenAsync,AssignRealmRoleAsync, the availability checks — allhttpClient.SendAsync(...)).GetRoleMembersAsync(line ~444) is the lone outlier:This news + disposes an
HttpClienton every call (socket/TIME_WAITleak, same family as #411/#433/#434) and mutatesDefaultRequestHeaders— the anti-pattern the rest of the class deliberately avoids.Fix
Use the injected
httpClientwith a per-requestHttpRequestMessage+Authorizationheader, matching every sibling method. No ctor change; URL construction unchanged.Acceptance
new HttpClient()inKeycloakAdminService;GetRoleMembersAsyncuses the injected client.Mock<HttpMessageHandler>harness — the stub sits on the injected client, so the test only passes once the injected client is used).Refs #411 (resource-leak availability bombs).
Resolved in spikersoft-backend PR #114 (merged to
master).GetRoleMembersAsyncnow uses the injectedHttpClientwith a per-requestAuthorizationheader, matching every sibling method — no more per-callnew HttpClient(). Guarded byKeycloakAdminServiceRoleMembersTests(stub on the injected client) + 21 existing Keycloak tests. This cleared the last non-benignnew HttpClient()in the backend. Closing.