demo(08-undisposed-httpclient): 08 — HttpClient field never disposed#157
demo(08-undisposed-httpclient): 08 — HttpClient field never disposed#157
Conversation
See scenarios/08-undisposed-httpclient/README.md for the expected verdict.
|
|
||
| public sealed class StripeWebhookClient | ||
| { | ||
| private readonly HttpClient _http = new HttpClient(); |
There was a problem hiding this comment.
GCI0024 — Resource Lifecycle
HttpClient allocated without using statement in src/OrderService/Payments/StripeWebhookClient.cs.
Evidence:
Line 5: private readonly HttpClient _http = new HttpClient();
💡 Suggested action: Wrap in using var resource = new HttpClient(...); to guarantee disposal.
Confidence: High | Severity: Warn
|
|
||
| public sealed class StripeWebhookClient | ||
| { | ||
| private readonly HttpClient _http = new HttpClient(); |
There was a problem hiding this comment.
GCI0038 — Dependency Injection Safety
Direct instantiation of injectable type
Evidence:
src/OrderService/Payments/StripeWebhookClient.cs line 5: private readonly HttpClient _http = new HttpClient();
💡 Suggested action: Register the type with the DI container and inject it via constructor.
Confidence: Low | Severity: Warn
|
|
||
| public sealed class StripeWebhookClient | ||
| { | ||
| private readonly HttpClient _http = new HttpClient(); |
There was a problem hiding this comment.
GCI0039 — External Service Safety
Direct HttpClient instantiation
Evidence:
Line 5: private readonly HttpClient _http = new HttpClient();
File src/OrderService/Payments/StripeWebhookClient.cs adds HttpClient usage with no timeout configuration.
💡 Suggested action: Use IHttpClientFactory.CreateClient() or typed clients registered in the DI container.
Confidence: High | Severity: Block | 2 occurrences
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 5ec3825ad2
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
|
|
||
| public sealed class StripeWebhookClient | ||
| { | ||
| private readonly HttpClient _http = new HttpClient(); |
There was a problem hiding this comment.
Dispose owned HttpClient or inject one from a factory
StripeWebhookClient allocates a HttpClient instance as a private field but never disposes it, and the class itself is not IDisposable. If this type is created repeatedly (for example, transiently in request scope), each instance leaves its handler/socket resources alive longer than intended, which can lead to connection exhaustion under load. Prefer injecting HttpClient (or IHttpClientFactory) or implementing disposal for the owned client.
Useful? React with 👍 / 👎.
08 — HttpClient field never disposed
Expected verdict: ❌ Fails — GauntletCI should fire GCI0024 (resource lifecycle).
What changed
A new
StripeWebhookClientclass holds aHttpClientas a privatefield that is constructed inline and never disposed:
The class itself does not implement
IDisposable, so the underlyingsocket handle outlives every request that uses it.
Why this is risky
HttpClientimplementsIDisposable. Owning one as a field withoutalso implementing
IDisposable(or routing throughIHttpClientFactory)leaks the socket pool slot for the lifetime of the process.
using/Dispose()pair anywhere in scope, exceptions thrownbefore the next request also leak any pending response stream.
StripeWebhookClient, soa single misbehaving callback can starve the whole socket pool.
What GauntletCI catches
GCI0024 Resource Lifecycle—new HttpClient(allocated as a fieldwith no
using, no surroundingDispose()call, and no nearbyIHttpClientFactoryreference.