Debug Service Threads Stuck in getrandom(): Thread States, Lock Contention, Evidence
Company: Alibaba
Role: Site Reliability Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
In an incident deep dive for a site reliability role, the interviewers asked the candidate to describe a real production incident and then drilled into the investigation: for example, how to check the state of the threads calling `getrandom()`, how to determine whether lock contention caused the problem, and how every data point was obtained, down to the command used to read each status metric.
The candidate's own incident was not reported, so this practice version fixes a scenario. Assume a Linux host where a service's requests have stalled, and stack samples show many of its threads in or near calls to `getrandom()`. Walk through the investigation.
### Clarifying Questions
- What language and runtime is the service written in (C or C++, Java, Go, Python)? The tools for reading thread stacks differ.
- Did the stall start right after a boot or deployment, or on a host that had been running for a long time?
- Is it one host or many, and did it begin after a kernel, library or container image change?
- Does the code call `getrandom()` directly, or through a library (TLS, UUID generation, a language's secure random API)?
- May we attach debuggers or tracers to the production process, or only read `/proc` and existing metrics?
### Part 1 — Inspect the state of the threads
Show how you find which threads are stuck, what state the kernel reports for each, and where each one is blocked, naming the command behind every observation.
```hint Ask the kernel first
Before reaching for a profiler, think about what `/proc` exposes for each individual thread of a process.
```
#### What This Part Should Cover
- Listing a process's threads with their kernel scheduling states
- User-space and kernel stacks, and the system call a thread is currently in
- Telling a thread blocked in a system call from one spinning on the CPU
- The command behind each observation, and what its output proves
### Part 2 — Prove or rule out lock contention
Explain how you determine whether lock contention, rather than the `getrandom()` call itself, caused the stall.
```hint Two different ways to wait
A thread can wait inside the kernel for a system call to return, or wait for a lock before it ever reaches the call. Think about how each looks in a stack and in a system call trace.
```
```hint Find the holder
Contention means one thread holds the lock while the others queue behind it. Think about how you would identify the holder and what it is doing.
```
#### What This Part Should Cover
- How lock waits and system-call blocking differ in stacks and traces
- Identifying the lock holder and what it is blocked on
- Checking whether the kernel's random number generator itself was making callers wait
- Quantifying wait time with low-overhead tools
### Part 3 — Back every data point and close the incident
The interviewers asked how every data point was obtained. Present the incident's conclusion (root cause, fix and prevention) with each claim tied to the command or metric that supports it.
```hint An evidence chain
For each sentence of your root-cause statement, ask which output you would show if an interviewer challenged it.
```
#### What This Part Should Cover
- A timeline and a root-cause statement, each claim backed by a specific output
- Immediate mitigation, a lasting fix, and how you verified the fix worked
- Prevention: monitoring and tests that would catch a recurrence
### What a Strong Answer Covers
- Correct use of `/proc`, stack dumps and tracing tools, with an accurate reading of their output
- A clear distinction between lock contention and blocking inside the system call, including the case where both happen together
- Hypotheses tested with evidence rather than asserted
- Awareness of tool overhead on a production host
- A concise, evidence-backed incident narrative with a fix and prevention
### Follow-up Questions
- The stall happens only on freshly booted virtual machines. What does that suggest, and how do you confirm it?
- strace slows the target process considerably. What lower-overhead tools would you use on a latency-sensitive production host?
- How would you capture the same evidence automatically the next time, before anyone logs in?
- How would you distinguish contention on a lock inside your process from contention on a lock inside the kernel?
Overview: A site reliability incident drill-down about a Linux service whose threads appear stuck in getrandom(). It asks how to inspect per-thread kernel states and stacks, how to determine whether lock contention or the system call itself caused the stall, and how to back every conclusion with the command that produced it.
Read the full Alibaba Site Reliability Engineer interview experience this question came from