Skip to content

Gateway crashes on unhandled fetch rejection - watchdog workaround #7042

@L8ton-crypto

Description

@L8ton-crypto

Bug

The gateway process crashes with an unhandled promise rejection when a network fetch call fails:

TypeError: fetch failed
    at node:internal/deps/undici/undici:15845:13
    at processTicksAndRejections (node:internal/process/task_queues:103:5)

This kills the entire gateway. On Windows, the scheduled task service does not auto-restart on crash, so the gateway stays dead until manually restarted.

Impact

  • Cron jobs miss their scheduled runs
  • All channels go offline
  • No automatic recovery

Environment

  • Clawdbot 2026.1.24-3
  • Windows 10 (x64)
  • Node.js v24.12.0
  • Gateway running as Windows Scheduled Task

Suggested Fix

The rejection should be caught — either a global process.on('unhandledRejection') handler or proper try/catch around network calls (likely Telegram polling or heartbeat HTTP requests).

Workaround: Watchdog Wrapper

We modified gateway.cmd to loop and auto-restart on crash with a 5-second delay:

@echo off
:loop
echo [%date% %time%] Starting Clawdbot Gateway...
"C:\Program Files\nodejs\node.exe" path\to\clawdbot\dist\entry.js gateway --port 18789
set EXIT_CODE=%ERRORLEVEL%
echo [%date% %time%] Gateway exited with code %EXIT_CODE%. Restarting in 5 seconds...
timeout /t 5 /nobreak >nul
goto loop

This ensures the gateway always comes back up within seconds. Could be worth integrating into the daemon install for Windows users.

Steps to Reproduce

  1. Run gateway on Windows as a scheduled task
  2. Wait for a transient network failure (DNS timeout, connection drop, etc.)
  3. Gateway crashes and does not restart

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions