Repository navigation
Description
Summary
The Grubify API POST /api/cart/{userId}/items (Add to Cart) endpoint is failing with System.OutOfMemoryException. The container app ca-grubify-ubqf2fbkeowr4 is repeatedly crashing due to a memory leak in CartController.AddItemToCart.
Impact
- Severity: High — all Add to Cart operations fail, blocking the entire checkout flow
- Affected
8000
endpoint:
POST /api/cart/{userId}/items - Affected resource: Container App
ca-grubify-ubqf2fbkeowr4(East US 2,rg-sre-lab) - Duration: Recurring — OOM events observed on 2026-05-20 (20:07–20:11 UTC, 21:19–21:22 UTC) and 2026-05-21 (18:59–19:21 UTC, ongoing)
Root Cause
Memory leak in CartController.cs lines 14 and 30–31.
The AddItemToCart method allocates a 10 MB byte[] buffer on every request and appends it to a static List<byte[]> RequestDataCache that is never cleaned up:
// Line 14 — static field that grows forever
private static readonly List<byte[]> RequestDataCache = new();
// Lines 30-31 — 10MB allocation on every AddItemToCart call
var requestData = new byte[10 * 1024 * 1024]; // 10MB buffer for request analytics
RequestDataCache.Add(requestData);With the container's 1 Gi memory limit, approximately ~75-100 Add to Cart requests exhaust available memory, causing System.OutOfMemoryException on all subsequent requests (including non-cart endpoints).
Evidence
Container Console Logs (Log Analytics — ContainerAppConsoleLogs_CL)
| Time Window (UTC) | OOM Exception Count |
|---|---|
| 2026-05-20 20:07–20:11 | 166 |
| 2026-05-20 21:19–21:22 | 125 |
| 2026-05-21 18:59–19:05 | 127 |
| 2026-05-21 19:18–19:21 | 129 |
Sample log entry:
System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown.
Cache growth logs (before OOM)
The console logs show the cache growing unboundedly before each crash:
Analytics cache: Added request data. Total entries: 66
Analytics cache: Added request data. Total entries: 67
...
Analytics cache: Added request data. Total entries: 75
[OOM crash follows]
At 75 entries × 10 MB = 750 MB, close to the 1 Gi limit.
Application Insights
App Insights requests and exceptions tables are empty for the affected time windows. This is expected — the telemetry SDK cannot flush when the managed heap is exhausted by OOM.
Container App Configuration
- Image:
acrcagrubifyubqf2fbkeowr4.azurecr.io/grubify-api:latest - CPU: 0.5 cores
- Memory: 1 Gi
- Status: Running (restarts after OOM, then re-accumulates until next crash)
Recommended Fix
- Remove the
RequestDataCachestatic field and the 10 MB allocation entirely — this "analytics cache" serves no real purpose and has no consumer:
// DELETE these lines from CartController.cs:
private static readonly List<byte[]> RequestDataCache = new();
// DELETE from AddItemToCart method:
var requestData = new byte[10 * 1024 * 1024];
RequestDataCache.Add(requestData);
Console.WriteLine($"Analytics cache: Added request data. Total entries: {RequestDataCache.Count}");
Console.WriteLine($"Cache size: {RequestDataCache.Count * 10}MB");-
Restart the container app after deploying the fix to clear the accumulated memory.
-
Consider adding memory usage monitoring/alerts to detect similar leaks earlier.
Affected Code
GrubifyApi/Controllers/CartController.cs— Lines 14, 30-34
Investigated by Azure SRE Agent
This issue was created by sre-agent-ubqf2fbkeowr4--a4798a0c
Tracked by the SRE agent here
Activity