📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š Interview question

You need a memory dump from a .NET 10 API running in production on Kubernetes or App Service. How do you capture it safely? Compare dotnet-dump, dotnet-gcdump, createdump on crash and dotnet-monitor collection rules, and explain how you deal with the process pause, file size, disk space and the personal data inside the dump, and how you analyse it offline.

Covers capturing dumps in production safely: dump types (full, heap, triage, gcdump), dotnet-dump, createdump environment variables, dotnet-monitor sidecars and triggers, pause and size impact, storage and Privacy Act handling, and offline analysis.

Intermediate Theory Intermediate dotnet-dump dotnet-monitor kubernetes memory-dump privacy-act production

🎯 Key points

  • Pick the dump type for the question: gcdump for leaks (no field values), heap/full for hangs and SOS, triage for crashes with less personal data
  • Capture pauses the process; full dump ≈ working set, heap dump ≈ managed heap + stacks, gcdump much smaller; take the instance out of rotation first
  • Crash dumps via DOTNET_DbgEnableMiniDump, DOTNET_DbgMiniDumpType and DOTNET_DbgMiniDumpName to a mounted volume; OOMKill writes none
  • dotnet-monitor as a sidecar sharing the diagnostic port: collection rules (trigger, actions, limits) and egress to Blob storage
  • Containers: kubectl debug --target or a sidecar; enough ephemeral storage; GCHeapHardLimit or a heap trigger before the pod limit
  • Dumps hold tokens, secrets and customer data: encrypted storage in-region (Australia East), restricted access, short retention, delete after
  • Analyse offline with dotnet-dump analyze (clrthreads, clrstack -all, dumpheap -stat, gcroot), Visual Studio or WinDbg with matching symbols

⏱ 30-second answer

First choose the dump type for the question: a gcdump (managed object graph only, no field values, usually tens of MB) for leaks; a heap or full dump for hangs, deadlocks and SOS analysis; a triage dump for crashes when you want less personal data. Capturing pauses the process for seconds; a full dump is roughly the size of the working set and a heap dump roughly the managed heap plus stacks, so I take the instance out of rotation, check there's disk space, and write to a mounted volume, not the container's ephemeral layer.

In containers I use dotnet-monitor as a sidecar, with collection rules that capture automatically on a trigger and egress to encrypted Blob storage, plus createdump environment variables for crashes. A heap dump contains tokens and customer data, so it's handled like production data: stored in-region, restricted, deleted after analysis. The trade-off is evidence versus impact and privacy.

πŸ—£ Full answer (senior)

How I would answer this in an interview

"I start with what I need the dump to answer, because that decides the type. For a slow memory leak I want a gcdump: dotnet-gcdump opens an EventPipe session that triggers a gen 2 GC, the runtime streams the managed object graph (types, sizes and references) as events while it walks the heap, and the tool saves that as a .gcdump file, usually tens of megabytes with no field values, so no customer data. For a hang or deadlock I need thread stacks and locks, so a heap or full dump with dotnet-dump collect --type Heap and SOS. For crashes I configure createdump through environment variables so the runtime writes a dump when it dies.

Then I think about impact. A heap or full dump suspends the process while memory is written out, which can be several seconds for a few gigabytes, and a gcdump runs a full blocking GC. A full dump is about the size of the working set, so a 3 GB process needs 3 GB of free disk, and in Kubernetes that can blow the pod's ephemeral storage limit and get it evicted, destroying the evidence. So I take the instance out of the load balancer or let the readiness probe fail first, write to a mounted volume, and copy the file out. For example, at [company] we [ran dotnet-monitor as a sidecar with a rule that captured a heap dump when the GC heap passed 2 GB and uploaded it to Blob storage], which meant [we had the evidence from a 3 am OOM before the pod restarted]. dotnet-monitor ships on its own release cadence alongside .NET servicing, so I check the current release's supported runtimes and trigger types before relying on a feature.

The part people forget is that a heap dump is a copy of everything in memory: bearer tokens, connection strings, Data Protection keys, customer names. Under the Privacy Act that's personal information, so the dump goes to encrypted storage in Australia East with access limited to the responders, never into a ticket or a laptop's Downloads folder, and it gets deleted when the investigation closes. If a dump might have exposed live tokens or secrets to someone outside that group, I treat them as compromised and rotate them. The mistake I see is treating dumps as harmless debug files."


Dump types

Type How Contains Typical size Use for
gcdump dotnet-gcdump collect -p <pid> Managed object graph: types, counts, sizes, references Tens to hundreds of MB Leaks, "what is holding memory"
Heap dotnet-dump collect --type Heap Managed heap, thread stacks, module list β‰ˆ managed heap + stacks Hangs, deadlocks, leaks with values
Full dotnet-dump collect --type Full All process memory incl. native β‰ˆ working set Native leaks, interop crashes
Mini --type Mini Thread stacks and modules Small Quick stacks only
Triage --type Triage Mini dump with personal data such as paths and strings stripped Small Crash stacks to share more widely

The four ways to capture

Tool When it fits Watch out for
dotnet-dump / dotnet-gcdump Someone is on the box, problem is happening now Needs the tool in the container or a debug container
createdump on crash (env vars) Crashes and fatal errors you can't predict Disk space at crash time; the kernel OOM killer's SIGKILL does not produce a dump
dotnet-monitor collection rules Containers; capture automatically on a condition Sidecar must share the diagnostic port; secure its API
App Service "Collect memory dump" (Diagnose and solve problems) App Service on Windows Process pause; storage location

Making it safe

Risk Mitigation
Process freezes during capture Remove from rotation first; capture one instance, not all
Disk or ephemeral storage full Mount an emptyDir with a size or a PVC; egress to Blob straight away
Pod OOMKilled before you capture dotnet-monitor heap trigger below the limit, or GCHeapHardLimitPercent so the runtime throws OOM (and createdump runs) before the kernel kills it
Personal data in the dump Prefer gcdump or triage; encrypted Blob in-region; RBAC; short retention; rotate exposed secrets
Wrong symbols at analysis time Keep PDBs from the build; symbol server; same runtime version

Production example

An order API on AKS was OOMKilled every few hours. A dotnet-monitor rule (System.Runtime gc-heap-size above 1,800 MB for 1 minute, one dump per hour at most) captured a 2.1 GB heap dump to Blob storage in Australia East; dumpheap -stat and gcroot on it showed 1.4 million cached PriceQuote objects held by a static dictionary, and the fix shipped the same day.

πŸ” What the interviewer is checking

Checks the candidate can get evidence from production without causing an outage or a data breach, and choose the right dump type.

Green flags

  • Picks gcdump, heap, full or triage based on the question
  • Mentions the process pause, file size and taking the instance out of rotation
  • Knows how to capture in containers (dotnet-monitor sidecar, kubectl debug, createdump env vars)
  • Treats dumps as sensitive data with storage, access and retention rules

Red flags

  • "Just RDP in and use Task Manager" as the only method
  • Unaware that dumps contain secrets and personal data
  • Expects a dump from an OOMKilled pod

πŸ“š Learn in depth

1. What happens when a dump is taken

On Linux, dotnet-dump collect asks the runtime over the diagnostic port (a Unix domain socket in $TMPDIR named dotnet-diagnostic-<pid>-...) to run createdump, which suspends the process's threads and reads its memory through /proc/<pid>/mem, writing an ELF core file. On Windows it uses MiniDumpWriteDump. The process is frozen for the whole write, so time grows with dump size and disk speed.

 dotnet-dump ──diagnostic IPC──► runtime in target process
                                        β”‚ launches createdump
                                        β–Ό
                          suspend threads ─► read memory ─► write core file
                                        β”‚
                                  resume process

dotnet-gcdump works differently: it starts an EventPipe session that triggers a gen 2 GC; while the GC walks the heap the runtime emits the object graph as events, and the tool builds the .gcdump file on its side. No process memory is copied, but the GC is blocking, so a big heap still pauses requests.

2. Crash dumps through environment variables

The runtime writes a dump on an unhandled exception or fatal error when configured:

DOTNET_DbgEnableMiniDump=1
DOTNET_DbgMiniDumpType=2          # 1 Mini, 2 Heap, 3 Triage, 4 Full
DOTNET_DbgMiniDumpName=/dumps/%e-%p-%t.dmp   # %e exe, %p pid, %t time
DOTNET_CreateDumpDiagnostics=1    # log createdump problems

It can't help when the kernel OOM killer sends SIGKILL: there's no chance to run code. For OOMKilled pods you need a trigger before the limit (dotnet-monitor) or a GCHeapHardLimit / GCHeapHardLimitPercent below the container limit so the runtime throws OutOfMemoryException first and createdump can run.

3. dotnet-monitor in containers

dotnet-monitor runs as a separate container in the same pod. Both share a volume for the diagnostic socket; the usual setup is the app connecting to dotnet-monitor in listen mode via DOTNET_DiagnosticPorts. It exposes an HTTP API (default port 52323) for /dump, /gcdump, /trace, /logs, and a metrics endpoint. Collection rules make it automatic:

Trigger  (EventCounter threshold, AspNetRequestDuration, AspNetResponseStatus, AspNetRequestCount)
   └─► Actions (CollectDump, CollectGCDump, CollectTrace, CollectLogs) ─► Egress provider (Azure Blob)
   └─► Limits  (ActionCount, ActionCountSlidingWindowDuration, RuleDuration)

The API must be authenticated (API key or Entra ID) and never exposed outside the pod network: it can dump memory. dotnet-monitor is released separately from the runtime, so check which release supports your runtime and which triggers it offers before relying on a feature.

4. Getting at a container with no tools

Chiseled and distroless images have no shell. Options: bake nothing in and use kubectl debug -it <pod> --image=mcr.microsoft.com/dotnet/sdk:10.0 --target=<container> to get an ephemeral container sharing the process namespace (the diagnostic socket lives in the target's /tmp, so you need access to it, e.g. via /proc/<pid>/root/tmp); or rely on the dotnet-monitor sidecar. Running as the same user ID matters for permissions.

5. Privacy and data handling

A heap or full dump contains every managed string: JWTs, connection strings resolved from Key Vault, request bodies, customer names and addresses. Treat it as production data covered by the Privacy Act 1988 and your data classification:

  • store in an encrypted, private Blob container in the same region (Australia East / Southeast);
  • grant access per incident, log access, and set a lifecycle rule to delete after N days;
  • analyse on a managed machine, never attach to a public ticket;
  • prefer gcdump (no values) or triage dumps when they answer the question;
  • if a dump leaked beyond the responders, rotate the secrets and revoke the tokens it could contain (short token lifetimes limit the damage), and assess it under the Notifiable Data Breaches scheme.

6. Analysing offline

dotnet-dump analyze api.dmp
> clrthreads            # managed threads, lock counts, exceptions
> clrstack -all         # every managed stack
> syncblk               # who owns which Monitor lock
> dumpheap -stat        # types by count and size
> gcroot <address>      # why an object is still alive

Use the same runtime major version and architecture as the dump. Visual Studio (Debug Managed Memory, Parallel Stacks) and WinDbg can also open .NET Linux core dumps. Open .gcdump files in Visual Studio, PerfView or dotnet-gcdump report.

7. When the capture itself fails

Symptom Likely cause Fix
Unable to connect to the process / no processes listed Tool can't see the diagnostic socket (different /tmp, different user, separate container) Same user ID; share /tmp or use /proc/<pid>/root/tmp; use kubectl debug --target
Permission denied / ptrace errors Container security context blocks ptrace (seccomp, missing SYS_PTRACE in older setups) Run as the same user; allow ptrace for the debug container only
Dump file truncated or zero bytes Disk or emptyDir filled during the write Size the volume above the working set; egress immediately
Pod evicted mid-capture Ephemeral storage limit exceeded Write to a sized volume, not the container layer
No crash dump after a crash OOMKill (SIGKILL), wrong path, or volume not writable Check DOTNET_CreateDumpDiagnostics=1 output; heap trigger before the limit
dotnet-monitor rule never fires Wrong counter name, app not connected to the socket, limits reached GET /processes on the monitor API; check its logs; review Limits

Rehearse this in staging: a capture you have never tried will fail at 3 am for one of these reasons.

Try it yourself

  1. Run an API in Docker, start a leak (add to a static list per request), and compare dotnet-gcdump and dotnet-dump --type Heap sizes and pause times while load is running.
  2. Set the createdump environment variables, throw an unhandled exception on a background thread, and open the dump.
  3. Add a dotnet-monitor sidecar to a kind or AKS pod with a rule on gc-heap-size and egress to Azurite or Blob storage.
  4. Search a heap dump for a JWT you sent in a request (dumpheap -type System.String plus dumpobj) to see why dumps are sensitive.
  5. Try kubectl debug --target against a chiseled image and capture a dump; then break it on purpose (fill the volume, wrong user) and read the errors.

πŸ’» Code

A Kubernetes pod with a dotnet-monitor sidecar that captures a heap dump automatically when the managed heap grows too large, plus crash dumps to a mounted volume.

# Deployment excerpt: app + dotnet-monitor sharing the diagnostic socket and a dump volume.
spec:
  containers:
    - name: api
      image: myregistry.azurecr.io/orders-api:1.42.0
      env:
        - { name: DOTNET_DiagnosticPorts, value: /diag/dotnet-monitor.sock }  # app connects to monitor
        - { name: DOTNET_DbgEnableMiniDump, value: "1" }                       # crash dumps
        - { name: DOTNET_DbgMiniDumpType, value: "2" }                         # 2 = heap
        - { name: DOTNET_DbgMiniDumpName, value: /dumps/%e-%p-%t.dmp }
      volumeMounts:
        - { name: diag, mountPath: /diag }
        - { name: dumps, mountPath: /dumps }
    - name: monitor
      image: mcr.microsoft.com/dotnet/monitor:9   # use the tag that matches your supported runtime
      args: ["collect", "--urls", "http://localhost:52323", "--metricUrls", "http://+:52325"]
      env:
        - { name: DOTNETMONITOR_DiagnosticPort__ConnectionMode, value: Listen }
        - { name: DOTNETMONITOR_DiagnosticPort__EndpointName, value: /diag/dotnet-monitor.sock }
        - { name: DOTNETMONITOR_Storage__DumpTempFolder, value: /dumps }
      volumeMounts:
        - { name: diag, mountPath: /diag }
        - { name: dumps, mountPath: /dumps }
        - { name: monitor-config, mountPath: /etc/dotnet-monitor }   # settings.json below, from a ConfigMap/Secret
  volumes:
    - { name: diag, emptyDir: {} }
    - name: dumps
      emptyDir: { sizeLimit: 6Gi }   # room for a dump without evicting the pod
    - { name: monitor-config, secret: { secretName: dotnet-monitor-settings } }
{
  "CollectionRules": {
    "HeapTooBig": {
      "Trigger": {
        "Type": "EventCounter",
        "Settings": { "ProviderName": "System.Runtime", "CounterName": "gc-heap-size", "GreaterThan": 1800, "SlidingWindowDuration": "00:01:00" }
      },
      "Actions": [ { "Type": "CollectDump", "Settings": { "Type": "WithHeap", "Egress": "incidentBlob" } } ],
      "Limits": { "ActionCount": 1, "ActionCountSlidingWindowDuration": "01:00:00" }
    }
  },
  "Egress": {
    "AzureBlobStorage": {
      "incidentBlob": {
        "AccountUri": "https://stincidentdumpsaue.blob.core.windows.net",
        "ContainerName": "dumps",
        "ManagedIdentityClientId": "<client-id>"
      }
    }
  }
}
# Manual capture from an ephemeral debug container sharing the process namespace
kubectl debug -it orders-api-7d9f -n orders --image=mcr.microsoft.com/dotnet/sdk:10.0 --target=api -- bash
dotnet tool install -g dotnet-dump dotnet-gcdump && export PATH=$PATH:~/.dotnet/tools
dotnet-gcdump collect -p 1 -o /tmp/orders.gcdump          # leak: graph only, no values
dotnet-dump collect -p 1 --type Heap -o /tmp/orders.dmp   # hang: stacks + heap

⚠ Common mistakes

  • Mistake: Taking a full dump of every instance at once. Why it is wrong: every capture freezes its process, so you cause a full outage. Instead: pull one instance out of rotation and dump only that one.
  • Mistake: Writing the dump to the container's writable layer. Why it is wrong: it can exceed ephemeral storage, get the pod evicted and lose the file. Instead: a sized emptyDir or volume, then egress to Blob storage.
  • Mistake: Expecting createdump to catch an OOMKill. Why it is wrong: the kernel's SIGKILL gives the runtime no chance to run. Instead: trigger on heap size before the limit, or set GCHeapHardLimit below the container limit.
  • Mistake: Using a full dump when a gcdump answers the question. Why it is wrong: bigger, longer pause, and full of personal data. Instead: gcdump for leaks; heap or full only when you need stacks or values.
  • Mistake: Attaching dumps to tickets or copying them to laptops. Why it is wrong: they contain tokens, secrets and customer data, a potential notifiable breach. Instead: encrypted in-region storage with RBAC and a deletion policy.
  • Mistake: Exposing the dotnet-monitor API without authentication or outside the pod. Why it is wrong: anyone who reaches it can download process memory. Instead: API key or Entra ID auth, bind to localhost, network policies.
  • Mistake: Analysing with a different runtime version or no symbols. Why it is wrong: SOS output is wrong or empty. Instead: matching runtime and architecture; keep build PDBs or use a symbol server.

πŸ› Senior insight: trade-offs

The senior point is that a dump is evidence with a cost: it pauses a production process and creates a sensitive file. So I decide in advance, not at 3 am: which dump types we allow, where they go, who can read them and how long they live, and I wire automatic capture (dotnet-monitor rules, createdump variables) into the platform so the evidence exists before anyone is paged. If we only ever take gcdumps for leaks, we rarely create personal data at all.

Approach When it fits Cost When not to
Manual dotnet-dump Live hang you can observe now Needs tooling access, pause Pod will restart before you get there
dotnet-monitor rules Containers, recurring or overnight issues Sidecar, config, securing its API Very small services where it's overkill
createdump on crash Unhandled exceptions, fatal errors Disk at crash time OOMKill (no dump is written)
App Insights Snapshot Debugger Exceptions in App Service with the classic SDK Small snapshots, limited scope OpenTelemetry-only apps: check current support first

πŸ”— Follow-ups the interviewer may ask

  1. When: Candidate mentions analysing the dump offline. Why: Checks they can read the dump once they have it: SOS commands and what to look for.
    How to answer

    When I can't attach a debugger, I take a dump: a snapshot of the process's memory, threads and stacks that I analyse offline. For a hang or a leak, dotnet-dump collect -p <pid> does it in seconds. For crashes, I enable automatic crash dumps with the DOTNET_DbgEnableMiniDump environment variables. On App Service I use Diagnose and solve problems, and in Kubernetes dotnet-monitor. Then I analyse with dotnet-dump analyze: clrstack -all and syncblk for hangs, dumpheap -stat and gcroot for leaks, pe for exceptions. Or I open the dump in Visual Studio and use the Threads and Parallel Stacks windows. Dumps contain customer data, so they're handled as sensitive.

  2. When: Candidate mentions gcdump for leaks. Why: Checks they can use dumps to find the root of a leak.
    How to answer

    First confirm a leak: memory keeps rising across GCs under steady load, rather than a cache warming up. Then decide managed or native: if the GC heap size (dotnet-counters) grows with the working set, it is managed; if the working set grows while the GC heap is flat, look at native memory. For managed leaks, take two dotnet-gcdump snapshots some time apart and compare which types grow, then use dotnet-dump with dumpheap -stat and gcroot to find what keeps them alive. Typical roots: static collections and caches, event subscriptions, timers, captured closures, DI root-scoped transients, and unbounded queues. Fix, then verify with the same metrics under load.

  3. When: Candidate mentions dotnet-monitor or traces. Why: Checks they know the wider production profiling toolset and its privacy risks.
    How to answer

    Safe production profiling means cheap signals always on and heavy captures rare, short and controlled.

    • Always on: runtime metrics and distributed traces through OpenTelemetry to Azure Monitor.
    • On demand: dotnet-monitor as a sidecar exposes trace, gcdump and dump endpoints over an authenticated API, with collection rules that capture automatically on a trigger (CPU, heap size, slow requests) and egress to Blob Storage.
    • Sampled continuous profiling: the Application Insights Profiler captures short traces and ties them to slow requests. The classic SDK version is GA; the OpenTelemetry-based profiler is still preview as of late 2026.

    I limit blast radius to one instance, and treat dumps as production data under the Privacy Act. The trade-off is evidence versus risk: a full dump answers anything but pauses the process and copies every secret in memory.

πŸ›  Real-world problems: how you handle them

Capturing the evidence for an overnight OOMKill before the pod restarts
Situation
An order API on AKS in Australia East, [6] replicas with a [2 GiB] memory limit, was OOMKilled roughly every [4 hours], usually overnight. Nobody was awake in time to capture anything, and restarts wiped the state.
Signals
Pod restart count rising with reason `OOMKilled`; Container Insights working set climbing in a sawtooth; `gc-heap-size` growing steadily between restarts; brief 502s at each restart.
Investigation
Added a dotnet-monitor sidecar with a collection rule on `System.Runtime` `gc-heap-size` above [1,500 MB] for 1 minute, one `WithHeap` dump per hour, egressing to an encrypted Blob container in Australia East with managed identity. Gave the pod a [6 GiB] `emptyDir` for the temporary dump file. The next night it captured a [1.7 GB] dump; `dotnet-dump analyze` showed `dumpheap -stat` dominated by `PriceQuote` and `gcroot` led to a static `ConcurrentDictionary` used as a cache with no eviction.
Resolution
Immediate: raised the memory limit and added a nightly rolling restart to stop the outages. Fix: replaced the dictionary with `HybridCache` with an expiry and size limit; memory flattened at [~600 MB].
Prevention
Kept the dotnet-monitor rule in the base Helm chart for every service; added a Blob lifecycle rule deleting dumps after [14 days] and restricted access to an incident group; added a heap-growth alert as a ticket; added a load test that checks memory after 1 hour.

How to tell it (STAR)

**S:** At [company] our order API on AKS was being OOMKilled every few hours, mostly overnight, and every restart destroyed the evidence. **T:** I [owned / was asked to lead] getting a dump we could actually analyse, safely. **A:** I added a dotnet-monitor sidecar with a rule that captured one heap dump when the GC heap passed [1.5 GB], wrote it to a sized volume and egressed it to encrypted Blob storage in Australia East, with access limited to the incident group and a 14-day deletion rule because dumps hold customer data. The first night's dump showed a static dictionary cache with no eviction holding [1.4 million] quotes. **R:** We replaced it with HybridCache with a size limit, memory stabilised at [about 600 MB], and OOMKills went from [6 a day] to zero.

More in Production Tools

Last updated 23 Nov 2026.

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me