Skip to content

Garbage collection WASM trap #56

Description

@asteurer

I've created a reproduction of the trap error here: https://github.com/asteurer/gc-trap-repro

Overview

When a long-lived Go component calls an import function that returns heap-allocated data often enough, this will trigger Go's garbage collector which then causes the component to trap with the following error:

Error: error while executing at wasm backtrace:
    0: 0x26bf0e - <unknown>!clock_time_get
    1: 0x26fecf - <unknown>!<wasm function 4>
    2:  0x8d661 - <unknown>!runtime.clock_time_get
    3:  0x8edf6 - <unknown>!runtime.nanotime1
    4:  0x54a4e - <unknown>!runtime.gcAssistAlloc1
    5:  0x54720 - <unknown>!runtime.gcAssistAlloc.func2
    6: 0x11ab50 - <unknown>!runtime.systemstack
    7:  0x53fed - <unknown>!runtime.gcAssistAlloc
    8:  0x2daee - <unknown>!runtime.deductAssistCredit
    9: 0x10e169 - <unknown>!runtime.mallocgc
   10: 0x115d30 - <unknown>!runtime.growslice
   11:  0x95cdf - <unknown>!runtime.__Pinner_.Pin
   12: 0x17b0b0 - <unknown>!go.bytecodealliance.org_pkg_wit_runtime.Allocate
   13: 0x17b884 - <unknown>!go.bytecodealliance.org_pkg_wit_runtime.cabiRealloc
   14: 0x17b9dd - <unknown>!cabi_realloc
   15: 0x26ff59 - <unknown>!<wasm function 15>
   16: 0x17ba0c - <unknown>!wit_component_wit_world.wasm_import_get_str
   17: 0x17bb78 - <unknown>!wit_component_wit_world.GetStr
   18: 0x17be64 - <unknown>!wit_component_export_wit_world.Run
   19: 0x17c065 - <unknown>!main.wasm_export_wit_world_run

Caused by:
    wasm trap: cannot leave component instance

Identified Workaround

The current workaround is to call runtime.GC() in the relevant export function(s)

@dicej

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions