mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 17:04:58 +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:
@@ -6,6 +6,7 @@ import { isWSL2Sync } from "../infra/wsl.js";
|
||||
export const TELEGRAM_DISABLE_AUTO_SELECT_FAMILY_ENV =
|
||||
"OPENCLAW_TELEGRAM_DISABLE_AUTO_SELECT_FAMILY";
|
||||
export const TELEGRAM_ENABLE_AUTO_SELECT_FAMILY_ENV = "OPENCLAW_TELEGRAM_ENABLE_AUTO_SELECT_FAMILY";
|
||||
export const TELEGRAM_DNS_RESULT_ORDER_ENV = "OPENCLAW_TELEGRAM_DNS_RESULT_ORDER";
|
||||
|
||||
export type TelegramAutoSelectFamilyDecision = {
|
||||
value: boolean | null;
|
||||
@@ -22,6 +23,11 @@ function isWSL2SyncCached(): boolean {
|
||||
return wsl2SyncCache;
|
||||
}
|
||||
|
||||
export type TelegramDnsResultOrderDecision = {
|
||||
value: string | null;
|
||||
source?: string;
|
||||
};
|
||||
|
||||
export function resolveTelegramAutoSelectFamilyDecision(params?: {
|
||||
network?: TelegramNetworkConfig;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
@@ -52,6 +58,49 @@ export function resolveTelegramAutoSelectFamilyDecision(params?: {
|
||||
return { value: null };
|
||||
}
|
||||
|
||||
/**
|
||||
* Resolve DNS result order setting for Telegram network requests.
|
||||
* Some networks/ISPs have issues with IPv6 causing fetch failures.
|
||||
* Setting "ipv4first" prioritizes IPv4 addresses in DNS resolution.
|
||||
*
|
||||
* Priority:
|
||||
* 1. Environment variable OPENCLAW_TELEGRAM_DNS_RESULT_ORDER
|
||||
* 2. Config: channels.telegram.network.dnsResultOrder
|
||||
* 3. Default: "ipv4first" on Node 22+ (to work around common IPv6 issues)
|
||||
*/
|
||||
export function resolveTelegramDnsResultOrderDecision(params?: {
|
||||
network?: TelegramNetworkConfig;
|
||||
env?: NodeJS.ProcessEnv;
|
||||
nodeMajor?: number;
|
||||
}): TelegramDnsResultOrderDecision {
|
||||
const env = params?.env ?? process.env;
|
||||
const nodeMajor =
|
||||
typeof params?.nodeMajor === "number"
|
||||
? params.nodeMajor
|
||||
: Number(process.versions.node.split(".")[0]);
|
||||
|
||||
// Check environment variable
|
||||
const envValue = env[TELEGRAM_DNS_RESULT_ORDER_ENV]?.trim().toLowerCase();
|
||||
if (envValue === "ipv4first" || envValue === "verbatim") {
|
||||
return { value: envValue, source: `env:${TELEGRAM_DNS_RESULT_ORDER_ENV}` };
|
||||
}
|
||||
|
||||
// Check config
|
||||
const configValue = (params?.network as { dnsResultOrder?: string } | undefined)?.dnsResultOrder
|
||||
?.trim()
|
||||
.toLowerCase();
|
||||
if (configValue === "ipv4first" || configValue === "verbatim") {
|
||||
return { value: configValue, source: "config" };
|
||||
}
|
||||
|
||||
// Default to ipv4first on Node 22+ to avoid IPv6 issues
|
||||
if (Number.isFinite(nodeMajor) && nodeMajor >= 22) {
|
||||
return { value: "ipv4first", source: "default-node22" };
|
||||
}
|
||||
|
||||
return { value: null };
|
||||
}
|
||||
|
||||
export function resetTelegramNetworkConfigStateForTests(): void {
|
||||
wsl2SyncCache = undefined;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user