Member-only story
When a Single Line Crashed Our Prod: A Real OOM Loop Bug Postmortem
Innocuous Code, Major Incident
3 min read 4 days ago
Not a Member Check out the free link : Friend Link
In a recent production deployment of our Spring Boot service, we added what looked like a harmless utility method during a routine refactor. The PR passed tests, got approved, and shipped. But within hours, alerts started firing — memory usage spiked, pods were restarting, and the system ground to a halt.
Let’s walk through what happened.
The Buggy Code
public List<String> getValues(String input) {
List<String> result = new ArrayList<>();
while (input != null) {
result.add(input);
input = input.trim(); // Looks innocent
}
return result;
}
What’s the Output?
If we run getValues(" Hello ")
, what do we expect?
trim()
removes whitespace.- But
input = input.trim()
on a string like"Hello"
returns the same object. - Now the condition
while (input != null)
never breaks, becauseinput
remains non-null and unchanged — leading to an infinite loop. - Add
.add(input)
inside, and memory usage explodes: every…