Skip to content

runtime: make many runtime panics fatal#5552

Merged
deadprogram merged 2 commits into
tinygo-org:devfrom
jakebailey:runtime-fatal-errors
Jul 25, 2026
Merged

runtime: make many runtime panics fatal#5552
deadprogram merged 2 commits into
tinygo-org:devfrom
jakebailey:runtime-fatal-errors

Conversation

@jakebailey

@jakebailey jakebailey commented Jul 24, 2026

Copy link
Copy Markdown
Member

In #5438, I made runtime panics recoverable.

But, I didn't think about the fact that because they previously were not recoverable, they had historically been used like fatal errors (throw in BigGo terms). This means that if a tinygo process OOMs, it won't crash... It will attempt to panic, and then bad things happen (panicking needs to allocate!), which I figured out due to a hang in regexp/syntax tests in #5550 on the qemu-riscv runner with limited memory.

So, introduce runtimeFatal and switch OOMs and many other things to it that should not have been recoverable panics.

Match the Go runtime by terminating instead of unwinding when an
allocator exhausts the heap. Recovering an OOM can leave allocator locks
held and cannot safely continue when the panic path itself needs memory.
Match the Go runtime by terminating for deadlocks, stack overflows,
runtime and GC invariants, invalid lock operations, and platform
initialization failures instead of routing them through panic/recover.

Keep language-level runtime errors and unsupported user operations
recoverable. Add crash coverage that verifies fatal errors bypass deferred
recover calls.
@jakebailey
jakebailey force-pushed the runtime-fatal-errors branch from 742c156 to 42f7278 Compare July 24, 2026 19:10

@dgryski dgryski left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@deadprogram

Copy link
Copy Markdown
Member

Thank you for working on this @jakebailey and to @dgryski for review. Now merging.

@deadprogram
deadprogram merged commit 16fc1ea into tinygo-org:dev Jul 25, 2026
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants