Skip to content

Commit 25f3e2f

Browse files
Juanclaude
andcommitted
Fix crash where arr timeouts kill web UI and main loop
Wrap per-instance job runs and download client jobs in try/except so a Sonarr/Radarr timeout logs an error and continues instead of crashing. Add main_with_restart() wrapper so even unexpected failures auto-recover after 30s while the web server stays up independently. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 513ad63 commit 25f3e2f

1 file changed

Lines changed: 19 additions & 3 deletions

File tree

main.py

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,17 @@ async def main():
8686

8787
# Run script for each instance
8888
for arr in settings.instances:
89-
await job_manager.run_jobs(arr)
89+
try:
90+
await job_manager.run_jobs(arr)
91+
except Exception as e:
92+
logger.error(f"Error running jobs on {arr.name}: {e}")
9093
logger.verbose("")
9194

9295
# Run download client jobs (these run independently of *arr instances)
93-
await job_manager.run_download_client_jobs()
96+
try:
97+
await job_manager.run_download_client_jobs()
98+
except Exception as e:
99+
logger.error(f"Error running download client jobs: {e}")
94100

95101
await event_bus.emit(Event(EventType.CYCLE_END, {
96102
"instances": [arr.name for arr in settings.instances],
@@ -100,14 +106,24 @@ async def main():
100106
await wait_next_run()
101107

102108

109+
async def main_with_restart():
110+
"""Run main loop with automatic restart on unexpected failures."""
111+
while True:
112+
try:
113+
await main()
114+
except Exception as e:
115+
logger.error(f"Main loop crashed: {e}. Restarting in 30 seconds...")
116+
await asyncio.sleep(30)
117+
118+
103119
async def start():
104120
"""Entry point that optionally runs web server alongside main loop."""
105121
if web_enabled:
106122
from src.web.app import start_web_server
107123
web_task = asyncio.create_task(
108124
start_web_server(settings, event_bus, trigger_event)
109125
)
110-
main_task = asyncio.create_task(main())
126+
main_task = asyncio.create_task(main_with_restart())
111127
await asyncio.gather(main_task, web_task)
112128
else:
113129
await main()

0 commit comments

Comments
 (0)