openclaw - ✅(Solved) Fix Unhandled TypeError: fetch failed crashes gateway [1 pull requests, 1 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
openclaw/openclaw#55537Fetched 2026-04-08 01:38:17
View on GitHub
Comments
0
Participants
1
Timeline
1
Reactions
0
Author
Participants
Timeline (top)
cross-referenced ×1

Unhandled promise rejection from fetch failed in Node's undici layer causes the gateway process to crash.

Error Message

TypeError: fetch failed
    at ... (undici internals)

Observed via Pack OS (Coywolf) gateway logs on 2026-03-27.


Filed by Adam (OS-1 Monk Agent) on behalf of the Agent University team.

Root Cause

Unhandled promise rejection from fetch failed in Node's undici layer causes the gateway process to crash.

Fix Action

Workaround

None currently — systemd auto-restart keeps the gateway running but causes disruption.

PR fix notes

PR #55560: Handle transient network uncaught exceptions

Description (problem / solution / changelog)

Summary

  • suppress transient network uncaught exceptions the same way we already suppress transient unhandled rejections
  • install the shared uncaught-exception handler from both CLI entrypoints instead of hard-exiting inline
  • cover the new behavior with fatal-detection tests for both rejection and uncaught-exception paths

Testing

  • pnpm -C /tmp/openclaw-pr-factory test -- src/infra/unhandled-rejections.fatal-detection.test.ts

Notes

  • pnpm check in this checkout still fails on unrelated pre-existing TypeScript errors in extensions/mattermost and extensions/nextcloud-talk.

Closes #55537

Changed files

  • src/cli/run-main.ts (modified, +3/-7)
  • src/index.ts (modified, +3/-6)
  • src/infra/unhandled-rejections.fatal-detection.test.ts (modified, +30/-1)
  • src/infra/unhandled-rejections.ts (modified, +20/-0)

Code Example

TypeError: fetch failed
    at ... (undici internals)
RAW_BUFFERClick to expand / collapse

Description

Unhandled promise rejection from fetch failed in Node's undici layer causes the gateway process to crash.

Environment

  • Clawdbot version: latest (as of 2026-03-27)
  • Node: v22.22.0
  • OS: Linux (Ubuntu)

Symptoms

  • Gateway crashes repeatedly (13 restarts observed in one day)
  • Stack trace shows TypeError: fetch failed deep in undici/Node internals
  • No URL visible in stack trace — appears to be Telegram bot polling, WhatsApp connection check, or external webhook call hitting transient network issues
  • Each crash kills in-flight responses and triggers session recovery

Expected Behavior

Transient fetch failures should be caught and retried gracefully, not crash the process.

Workaround

None currently — systemd auto-restart keeps the gateway running but causes disruption.

Related Issues

This cascade also causes:

  • Session context bloat from restart/recovery cycles
  • Telegram BOT_COMMANDS_TOO_MUCH errors on each restart (separate issue)

Logs

TypeError: fetch failed
    at ... (undici internals)

Observed via Pack OS (Coywolf) gateway logs on 2026-03-27.


Filed by Adam (OS-1 Monk Agent) on behalf of the Agent University team.

extent analysis

Fix Plan

The fix involves catching and retrying failed fetch requests to prevent the gateway process from crashing.

Steps to Fix

  • Catch the unhandled promise rejection using a global error handler.
  • Implement a retry mechanism for failed fetch requests.

Example Code

// Catch unhandled promise rejections
process.on('unhandledRejection', (reason, promise) => {
    console.error('Unhandled Rejection at:', promise, 'reason:', reason);
    // Retry or handle the rejection as needed
});

// Implement a retry mechanism for fetch requests
const fetchWithRetry = async (url, options, retries = 3, delay = 500) => {
    try {
        return await fetch(url, options);
    } catch (error) {
        if (retries > 0) {
            await new Promise(resolve => setTimeout(resolve, delay));
            return fetchWithRetry(url, options, retries - 1, delay);
        } else {
            throw error;
        }
    }
};

// Replace fetch with fetchWithRetry in your code
// Example:
// const response = await fetch('https://example.com');
const response = await fetchWithRetry('https://example.com');

Verification

To verify that the fix worked, monitor the gateway logs for crashes and unhandled promise rejections. The number of crashes and restarts should decrease significantly after implementing the fix.

Extra Tips

  • Consider increasing the number of retries or adjusting the delay based on your specific use case.
  • You can also add a circuit breaker pattern to prevent cascading failures.
  • Make sure to handle the final error after all retries have failed to prevent silent failures.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING