Skip to main content
IncidentPaged 18:02 UTC, Tuesday (14th restart this week)

OOM-killed every 16 hours — telemetry buffer grew to 2 GB

Service: background-worker (Python, systemd-managed)

Symptom: Worker RSS climbs from 240 MB at boot to 2.1 GB over ~16 hours, then OOM-killed. systemd restarts. Cycle repeats. No request-handler leak found in heap dumps.

The code that's running in prod

# telemetry.py
# Background telemetry buffer — accumulates events from every
# request and flushes to an external ingestion endpoint every 60s.

import threading
import time
import requests

_buffer: list = []
_lock = threading.Lock()


def record_event(event):
    """Called from every request handler."""
    with _lock:
        _buffer.append(event)


def flush_loop():
    """Background thread: ship the buffer every 60 seconds."""
    while True:
        time.sleep(60)
        with _lock:
            if not _buffer:
                continue
            batch = list(_buffer)
        try:
            requests.post(
                "https://telemetry.example.com/ingest",
                json=batch,
                timeout=5,
            )
            with _lock:
                _buffer.clear()
        except Exception:
            pass   # try again on the next cycle

Log dashboard (last 60 seconds)

02:00:00INFO[worker]RSS 240 MB (baseline at boot)
02:00:42INFO[telemetry]Flush 1,240 events → 200 OK
06:00:00INFO[worker]RSS 280 MB
12:01:18WARN[telemetry]Flush 1,180 events → 502 Bad Gateway (ingestion endpoint down)
12:02:21WARN[telemetry]Flush 2,420 events → 502 (cumulative; previous flush failed)
14:00:00WARN[worker]RSS 480 MB; events buffered: 168,000
16:30:00WARN[telemetry]Flush 487,000 events → 502 Bad Gateway
17:45:00WARN[worker]RSS 1.9 GB; buffered: 1,200,000 events
18:02:14ERROR[kernel]Out of memory: Killed process 'worker' (RSS 2.1 GB)
18:02:14INFO[systemd]worker.service: main process exited; restart triggered (attempt 14 this week)

Pick the root cause

Four candidates. Three are plausible but mistake symptom for cause. Pick what you'd write in the postmortem timeline.