mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 23:14:31 +00:00
fix(telegram): add dnsResultOrder=ipv4first default on Node 22+ to fix fetch failures (#5405)
Merged via /review-pr -> /prepare-pr -> /merge-pr.
Prepared head SHA: 71366e9532
Co-authored-by: Glucksberg <80581902+Glucksberg@users.noreply.github.com>
Co-authored-by: obviyus <22031114+obviyus@users.noreply.github.com>
Reviewed-by: @obviyus
This commit is contained in:
@@ -1,29 +1,50 @@
|
||||
import * as dns from "node:dns";
|
||||
import * as net from "node:net";
|
||||
import type { TelegramNetworkConfig } from "../config/types.telegram.js";
|
||||
import { resolveFetch } from "../infra/fetch.js";
|
||||
import { createSubsystemLogger } from "../logging/subsystem.js";
|
||||
import { resolveTelegramAutoSelectFamilyDecision } from "./network-config.js";
|
||||
import {
|
||||
resolveTelegramAutoSelectFamilyDecision,
|
||||
resolveTelegramDnsResultOrderDecision,
|
||||
} from "./network-config.js";
|
||||
|
||||
let appliedAutoSelectFamily: boolean | null = null;
|
||||
let appliedDnsResultOrder: string | null = null;
|
||||
const log = createSubsystemLogger("telegram/network");
|
||||
|
||||
// Node 22 workaround: enable autoSelectFamily to allow IPv4 fallback on broken IPv6 networks.
|
||||
// Many networks have IPv6 configured but not routed, causing "Network is unreachable" errors.
|
||||
// See: https://github.com/nodejs/node/issues/54359
|
||||
function applyTelegramNetworkWorkarounds(network?: TelegramNetworkConfig): void {
|
||||
const decision = resolveTelegramAutoSelectFamilyDecision({ network });
|
||||
if (decision.value === null || decision.value === appliedAutoSelectFamily) {
|
||||
return;
|
||||
// Apply autoSelectFamily workaround
|
||||
const autoSelectDecision = resolveTelegramAutoSelectFamilyDecision({ network });
|
||||
if (autoSelectDecision.value !== null && autoSelectDecision.value !== appliedAutoSelectFamily) {
|
||||
if (typeof net.setDefaultAutoSelectFamily === "function") {
|
||||
try {
|
||||
net.setDefaultAutoSelectFamily(autoSelectDecision.value);
|
||||
appliedAutoSelectFamily = autoSelectDecision.value;
|
||||
const label = autoSelectDecision.source ? ` (${autoSelectDecision.source})` : "";
|
||||
log.info(`autoSelectFamily=${autoSelectDecision.value}${label}`);
|
||||
} catch {
|
||||
// ignore if unsupported by the runtime
|
||||
}
|
||||
}
|
||||
}
|
||||
appliedAutoSelectFamily = decision.value;
|
||||
|
||||
if (typeof net.setDefaultAutoSelectFamily === "function") {
|
||||
try {
|
||||
net.setDefaultAutoSelectFamily(decision.value);
|
||||
const label = decision.source ? ` (${decision.source})` : "";
|
||||
log.debug(`telegram: autoSelectFamily=${decision.value}${label}`);
|
||||
} catch {
|
||||
// ignore if unsupported by the runtime
|
||||
// Apply DNS result order workaround for IPv4/IPv6 issues.
|
||||
// Some APIs (including Telegram) may fail with IPv6 on certain networks.
|
||||
// See: https://github.com/openclaw/openclaw/issues/5311
|
||||
const dnsDecision = resolveTelegramDnsResultOrderDecision({ network });
|
||||
if (dnsDecision.value !== null && dnsDecision.value !== appliedDnsResultOrder) {
|
||||
if (typeof dns.setDefaultResultOrder === "function") {
|
||||
try {
|
||||
dns.setDefaultResultOrder(dnsDecision.value as "ipv4first" | "verbatim");
|
||||
appliedDnsResultOrder = dnsDecision.value;
|
||||
const label = dnsDecision.source ? ` (${dnsDecision.source})` : "";
|
||||
log.info(`dnsResultOrder=${dnsDecision.value}${label}`);
|
||||
} catch {
|
||||
// ignore if unsupported by the runtime
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -46,4 +67,5 @@ export function resolveTelegramFetch(
|
||||
|
||||
export function resetTelegramFetchStateForTests(): void {
|
||||
appliedAutoSelectFamily = null;
|
||||
appliedDnsResultOrder = null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user