Skip to content

Commit 090f8ac

Browse files
committed
Added crashing container app
1 parent 9d90de6 commit 090f8ac

File tree

2 files changed

+41
-0
lines changed

2 files changed

+41
-0
lines changed

crashing-app/Dockerfile

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
FROM python:3.9-slim-buster
2+
3+
WORKDIR /app
4+
5+
COPY app.py .
6+
7+
CMD ["python", "app.py"]

crashing-app/app.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import time
2+
import os
3+
import sys
4+
5+
def simulate_app():
6+
"""Simulates an application that crashes deterministically."""
7+
8+
# Simulate out-of-memory (OOM) kill (likely to be fixed with resource limits)
9+
print("Simulating OOM kill (allocating 600MB)...")
10+
big_list = [bytearray(1024 * 1024) for _ in range(600)] # Roughly 600MB
11+
time.sleep(1) # To show the message before crash.
12+
13+
14+
# Simulate a crash due to an environment variable being absent
15+
print("Simulating missing environment variable 'REQUIRED_ENV_VAR'...")
16+
if not os.environ.get("REQUIRED_ENV_VAR"):
17+
print("Environment variable REQUIRED_ENV_VAR not set. Exiting.")
18+
sys.exit(1)
19+
20+
# Simulate a crash due to a file not existing.
21+
print("Simulating missing file 'missing_file.txt'...")
22+
try:
23+
with open("/data/missing_file.txt", "r") as f:
24+
pass
25+
except FileNotFoundError:
26+
print("missing_file.txt not found. Exiting")
27+
sys.exit(1)
28+
29+
# Simulate normal operation (this will never be reached in this deterministic version)
30+
print("Application running normally...")
31+
time.sleep(5)
32+
33+
if __name__ == "__main__":
34+
simulate_app()

0 commit comments

Comments
 (0)