Skip to content

Kafka Producer Leak Causing Broker OOM on Astronomy Shop - #935

Merged
Saadmrp1038 merged 55 commits into
SREGym:mainfrom
vsmart-06:main
Jul 22, 2026
Merged

Saadmrp1038 merged 55 commits into
SREGym:mainfrom
vsmart-06:main

Conversation

@vsmart-06

@vsmart-06 vsmart-06 commented Jul 13, 2026 •

Copy link
Copy Markdown
Contributor

Implements #867

This PR adds a new SREGym problem, kafka_producer_leak, inspired by a real PagerDuty incident where excessive Kafka producer creation caused broker heap exhaustion.

Real-World Failure Story

Postmortem link: https://www.pagerduty.com/eng/august-28-kafka-outages-what-happened-and-how-were-improving/

In August 2025, PagerDuty experienced a major platform outage caused by a Kafka producer leak. A new feature introduced a bug where a fresh Kafka producer was instantiated per API request rather than reusing a shared instance. At peak traffic this generated millions of producer connections per hour. The Kafka broker's JVM heap filled up tracking metadata for all these producers, triggering garbage collection thrashing and eventually full broker unavailability. Since Kafka was central to nearly every async operation at PagerDuty, the outage cascaded platform-wide. Critically, an initial mitigation that simply restarted the broker failed because the leaking producers immediately re-exhausted memory - the root cause had to be addressed directly.

How the failure is simulated on SREGym

The problem targets the checkout deployment in the astronomy-shop namespace.

Fault injection

  1. Patches the Kafka deployment to raise KAFKA_MESSAGE_MAX_BYTES to 20MB, allowing oversized messages through.
  2. Adds an order-creator sidecar to the checkout deployment that spawns 20 threads, each creating a new idempotent Kafka producer per iteration and sending a 10MB payload to the orders topic.

The concurrent large-message sends exhaust the broker's JVM heap through network receive buffer allocation pressure, triggering an OOMKill.

Recovery removes the sidecar and reverts KAFKA_MESSAGE_MAX_BYTES, then force-deletes the old checkout pod to break the rolling update deadlock caused by the broker being unavailable during the update.

Problem runtime behavior and mitigation oracle

After injection, the Kafka broker OOMKills repeatedly (exit code 137). The same behaviour may be observed in the accounting and fraud-detection pods as well. The order-creator sidecar logs show hundreds of concurrent librdkafka producer instances terminating simultaneously with undelivered 10MB messages, directly implicating the sidecar as the cause.

The mitigation oracle (KafkaProducerLeakOracle) inherits MitigationOracle and additionally checks that the order-creator container is absent from the checkout deployment spec and that the broker pod is healthy.
The canonical mitigation is removing the order-creator sidecar from the checkout deployment.

Notes

  1. I definitely tested out the problem manually and I can see everything working, but I don't have access to any keys (that I'm aware of) to test it out with an actual agent. Any suggestions to test that out would be much appreciated!
  2. Right now I have a small Python script that creates the producers with the large payloads in the sidecar container. While investigated various approaches at implementing the problem, I found out that if I used a custom Java image instead, then the same outcome is observed, but the logs that come with the Python version are no longer visible, which may make the problem significantly more difficult for an agent to detect.

/validate-problem kafka_producer_leak

vsmart-06 and others added 30 commits June 5, 2026 12:45
* Add mutating_webhook_resource_limits problem

* Add mutating_webhook_resource_limits to Problem List

* mutating_webhook_resource_limits problem docstring fix

Removed incorrect information about mitigation options.

* Additions to mutating_webhook_limits_resource_limits problem

 - Memory limit/request patching before activating the webhook
 - Decoy pods for increased complexity

* More additions to mutating_webhook problem

 - Make decoys realisticly named
 - Similar minor changes

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
* add the the probem redundency

* base.

* the fixed and dynamic app name are fixed. hte namespace are also fixed.

* unessessry formating is reverted.

* unessessry formating is reverted.

* formating correction.

* formating correction.

* formating correction.

* add fault injection decorator markers to test_problem_bsae.py

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
* add file_descriptor_exhaustion problem

* Modify fault injection and recovery methods

* Fix fault recovery

* Change fault injection method
Add fault injection by flooding connections

* Update fault injection method and add custom oracle

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
* finalizzer code is reaoslve dadlock benchmark.

* yaml file corrected.

* reverting hte comments back to their place.

* read only rbac

* controller log is generalized and avoiding any sregym related name exposing.

* applied ruff linter formatter accordingly.

* replace metadata naming and includding all the oprations on mitigation side.

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
…EGym#851)

* Add secret rotation stale env credentials problem

* Simplify secret rotation mitigation oracle checks

* Require rotated PostgreSQL in oracle

* Fix stale DB credential rotation shortcuts

  - Remove old password from postgresql-init ConfigMap
  - Keep PostgreSQL password rotation durable after pod restart
  - Reject mitigations that revert otelu to the old password
  - Remove old password leaks from unrelated pods

* Fix fault recovery to satisfy the oracle

* Fix problem registry import ordering

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
…REGym#886)

* Add cumulative_admission_webhook_timeout_hotel_reservation problem

* Pin webhook backends to worker nodes via nodeAffinity

* Make webhook backends realistic admission services

Replace the dummy webhook backends with HTTPS admission servers that terminate TLS using Secret-mounted certificates, validate AdmissionReview

requests, and return proper admission responses. Certificates are signed by the same CA referenced in each webhook's `caBundle`, with SANs

covering the backend Service DNS names.

The admission logic enforces a trusted image registry allowlist and a

per-container CPU limit. All Hotel Reservation workloads satisfy these

policies, so the webhooks remain transparent during normal operation and

recovery.

Also:
* Vary webhook `timeoutSeconds` (12, 8, 11, 9) to make the cumulative
  timeout less obvious.

* Rename the CA CN from `sregym-webhook-ca` to
  `compliance-webhook-ca`.

* Remove a duplicate `rule.from_` check in the oracle.

* Fix create-or-replace handling for webhooks, NetworkPolicies,
  Deployments, and Services so re-injection updates existing resources
  instead of failing or silently skipping changes.

* Model the fault as a missing apiserver NetworkPolicy allow

* Model the fault as a missing apiserver allow with a near-miss policy

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Labelling a namespace pod-security.kubernetes.io/enforce=restricted leaves
running pods untouched but makes the apiserver reject recreated pods that run
as root / set no seccomp profile, so a deployment silently goes
under-replicated. Unlike the existing webhook problems, the policy is enforced
by the apiserver via a namespace label, not a webhook config.
* add copilot cli agent

* remove -s flag
* fix(mcp): broaden MCP retry exceptions and return error instead of raising

* fix(ci): strip CRLF from PR description before parsing problem ID
* Fix custom kind cluster detection

* Handle failed kind detection output
munimthahmid and others added 11 commits July 12, 2026 22:48
* Support local LLM endpoints for Stratus

* Prefer env vars for local LLM endpoints

* Support local LLM endpoints for OpenCode

* Route local endpoints into agent containers

* Normalize OpenCode local judge models

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
* add support for ATIF trajectory conversion and normalization, add claudecode adapter

* fix: make _finish_problem idempotent

* isolate .codex mount in container runner

* better temp dir cleanup

* add codex adapter

* add opencode adapter

* add copilot adapter

* add stratus adapter

* fix antropic caching for stratus

* add gemini adapter

* store normalized ATIF trajectories in SQLite indexed by problem type

* edge tests

* bump litellm, tikoken

* update docker lib versions
* adding clock drift problem

* fixing race condition causing sidecar log delay

* fixing recover_fault to reverse time sync removal applied, improve cleanup

* global cleanup added + fixed restoration for node_clock_drift problem

* fixing mitigation oracle to ensure correct node checked

* adding problem to non emulated cluster problems list

* extending wait

* indentation error fix

* fixing time restoration in global cleanup

* adding in check to make sure it picks worker node

* adding another control plane filter, fixing clock step-back in global recovery

* increase sidecar rollout timeout, make podnames/labels generic, idempotancy check

* formatting fixes

* format fix

* fix

* fix ruff check/format issues

---------

Co-authored-by: Saad Mohammad Rafid Pial <[email protected]>
Finished Kafka producer leak problem
@Saadmrp1038
Saadmrp1038 self-requested a review July 14, 2026 02:42
@Saadmrp1038 Saadmrp1038 added the problem Adding a new problem to the benchmark label Jul 14, 2026

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vsmart-06 Thanks for the effort! I left some inline comments below. Mainly about oracle behavior and fault injection handling. Please ping me when you have addressed them.

Comment thread sregym/generators/fault/inject_app.py Resolved
@vsmart-06
vsmart-06 requested a review from Saadmrp1038 July 18, 2026 00:19

@Saadmrp1038 Saadmrp1038 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the issues I mentioned before are now fixed. Only two nits about the large sleep values remain. We should poll instead whenever possible.

Comment thread sregym/generators/fault/inject_app.py Resolved
@Saadmrp1038

Copy link
Copy Markdown
Collaborator

Works great now!

@Saadmrp1038
Saadmrp1038 merged commit 01d1e79 into SREGym:main Jul 22, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

problem Adding a new problem to the benchmark

Projects

None yet

Development

Successfully merging this pull request may close these issues.