Skip to content
This repository was archived by the owner on Oct 9, 2026. It is now read-only.

fix: no recovered nil dereference on each Telegram API call - #30

Merged
mekjr1 merged 2 commits into
mainfrom
fix/telegram-api-fault
Oct 7, 2026
Merged

mekjr1 merged 2 commits into
mainfrom
fix/telegram-api-fault

Conversation

@mekjr1

@mekjr1 mekjr1 commented Oct 7, 2026

Copy link
Copy Markdown
Contributor

On windows-latest, CI crashed once in the Telegram tests with fatal error: found pointer to free object (run 37564359695), and passed on rerun.

Cause. telego's performRequest builds response.String() for a debug log before checking the log level. A successful response's Error is a nil *telegoapi.Error, and String() formats it with %v, so fmt calls (*Error).Error() on nil, which dereferences it. fmt recovers that panic silently. That is a recovered hardware fault on every successful Telegram API call, in production too: polling, every send.

On Windows hosts whose CPUs have AMX, recovering a hardware fault can corrupt the heap below the goroutine stack, and a later GC throws exactly this error: golang/go#81238. The fix is open in Go (CL 828724), not released. Our crash matches the issue's case: windows/amd64 on GitHub's runners, a size-16 span, intermittent by host. GitHub's Windows pool includes AMX Xeons, and so does any Windows server or VM on a recent Xeon.

Fix. The bot's API caller gives every response an Error (errorFillingCaller), so the debug formatting never dereferences nil. telego only reads a successful response's Error under WithWarnings(), which Compa doesn't use. The caller is built as telego would build it: its fasthttp client, or net/http with a proxy as before. That makes fasthttp a direct dependency in go.mod. The Telegram tests wrap their stub callers the same way.

Evidence. dlv trace --test 'runtime\.panicmem' over the Telegram tests: 52 recovered faults before, all from telegoapi.(*Error).Error <- telegoapi.Response.String; 0 after. I couldn't reproduce the crash locally: no AMX on this machine; 210 stress runs with GOGC=5, clobberfree and checkptr were clean.

Test: TestErrorFillingCaller.

mekjr1 added 2 commits October 7, 2026 11:18
telego formats every response's Error for a debug log whatever the log level, and a successful response's Error is nil, so fmt recovered a nil dereference on each API call. On Windows hosts whose CPUs have AMX, recovering such a hardware fault can corrupt the heap below the goroutine stack (golang/go#81238); the windows-latest CI job crashed once in the Telegram tests with 'found pointer to free object'. The bot's API caller now gives each response an Error. The caller is built as telego would build it: its fasthttp client, or net/http with a proxy.
@mekjr1
mekjr1 force-pushed the fix/telegram-api-fault branch from a5fbf2e to 9c883f2 Compare October 7, 2026 17:19
@mekjr1
mekjr1 merged commit c556e14 into main Oct 7, 2026
12 checks passed
@mekjr1
mekjr1 deleted the fix/telegram-api-fault branch October 7, 2026 17:56
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant