tao-shen Claude Opus 4.6 commited on
Commit
812bd8f
Β·
1 Parent(s): 429c637

fix: write DNS results to /etc/hosts for undici/fetch compatibility

Browse files

Telegram's grammY library uses undici (Node 22 built-in fetch) which
bypasses dns.lookup monkey-patching. Writing resolved IPs to /etc/hosts
ensures all DNS clients (including undici) can reach api.telegram.org.

Also chmod 666 /etc/hosts in Dockerfile so the node user can write to it.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>

Files changed (2) hide show
  1. Dockerfile +1 -0
  2. scripts/dns-resolve.py +11 -0
Dockerfile CHANGED
@@ -14,6 +14,7 @@ RUN echo "[build][layer1] System deps + tools..." && START=$(date +%s) \
14
  && chown node:node /app \
15
  && mkdir -p /home/node/.openclaw/workspace /home/node/.openclaw/credentials \
16
  && chown -R node:node /home/node \
 
17
  && echo "[build][layer1] System deps + tools: $(($(date +%s) - START))s"
18
 
19
  # ── εˆ‡ζ’εˆ° node η”¨ζˆ·οΌˆεŽη»­ζ‰€ζœ‰ζ“δ½œιƒ½δ»₯ node θΊ«δ»½οΌŒζ— ιœ€ chown)───────────────
 
14
  && chown node:node /app \
15
  && mkdir -p /home/node/.openclaw/workspace /home/node/.openclaw/credentials \
16
  && chown -R node:node /home/node \
17
+ && chmod 666 /etc/hosts \
18
  && echo "[build][layer1] System deps + tools: $(($(date +%s) - START))s"
19
 
20
  # ── εˆ‡ζ’εˆ° node η”¨ζˆ·οΌˆεŽη»­ζ‰€ζœ‰ζ“δ½œιƒ½δ»₯ node θΊ«δ»½οΌŒζ— ιœ€ chown)───────────────
scripts/dns-resolve.py CHANGED
@@ -94,6 +94,17 @@ def main() -> None:
94
  with open(output_file, "w") as f:
95
  json.dump(results, f, indent=2)
96
 
 
 
 
 
 
 
 
 
 
 
 
97
  print(f"[dns] Resolved {len(results)}/{len(DOMAINS)} domains -> {output_file}")
98
 
99
 
 
94
  with open(output_file, "w") as f:
95
  json.dump(results, f, indent=2)
96
 
97
+ # Also write to /etc/hosts so undici/fetch (which bypasses dns.lookup) works
98
+ if results:
99
+ try:
100
+ with open("/etc/hosts", "a") as f:
101
+ f.write("\n# === HuggingClaw DoH resolved domains ===\n")
102
+ for domain, ip in results.items():
103
+ f.write(f"{ip} {domain}\n")
104
+ print(f"[dns] Wrote {len(results)} entries to /etc/hosts")
105
+ except PermissionError:
106
+ print("[dns] WARNING: cannot write /etc/hosts (permission denied)")
107
+
108
  print(f"[dns] Resolved {len(results)}/{len(DOMAINS)} domains -> {output_file}")
109
 
110