File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ FROM python:3.9-slim-buster
2+
3+ WORKDIR /app
4+
5+ COPY app.py .
6+
7+ CMD ["python" , "app.py" ]
Original file line number Diff line number Diff line change 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 ()
You can’t perform that action at this time.
0 commit comments