carsonfarmer opened PR #14319 from carsonfarmer:cf/adapter-gc-clocks-timers to bytecodealliance:main:
Go can collect garbage during
cabi_realloc. The pause added by #13563 covers monotonic time, but GC termination also reads realtime, and restarting the scheduler performs a nonblocking poll once timers initialize netpoll. Both paths currently call host imports and trap.Cache realtime clock reads while paused, preserving normal host reads when unpaused. Answer a single relative zero-timeout clock subscription directly while paused; return
NOTSUPfor other paused polls. Keep the existing pause export and component import restrictions. The allocation-state getter is declared safe because its generated implementation only reads a nonshared global whose writers preserve valid enum values.The tests cover deterministic clock pause/resume, immediate-event contents for both clocks, and rejection of future timers while paused. A companion Go fixture exercises real GC during imported allocation. It fails with the released adapter, still fails at timer polling with only realtime caching fixed, and passes with both changes on Go 1.26.3 and 1.27.1.
Validation: release adapter build, strict adapter Clippy, formatting, and the sync/async adapter tests. The Go regression is tested separately with the built adapter.
This is deliberately limited to clock reads and a single immediate timer poll. It does not support arbitrary I/O during canonical allocation. The adapter's internal bootstrap-allocation branches are reviewed but not directly forced by these guest tests.
Related: #13563, #12112, https://github.com/bytecodealliance/componentize-go/issues/56, https://github.com/bytecodealliance/componentize-go/pull/60, and https://github.com/bytecodealliance/go-pkg/pull/7.
Fixes #14318.
Companion regression: https://github.com/bytecodealliance/componentize-go/issues/77.
carsonfarmer requested rvolosatovs for a review on PR #14319.
carsonfarmer requested dicej for a review on PR #14319.
carsonfarmer requested wasmtime-core-reviewers for a review on PR #14319.
carsonfarmer requested wasmtime-wasi-reviewers for a review on PR #14319.
carsonfarmer edited PR #14319:
Go can collect garbage during
cabi_realloc. The pause added by #13563 covers monotonic time, but GC termination also reads realtime, and restarting the scheduler performs a nonblocking poll once timers initialize netpoll. Both paths currently call host imports and trap.Cache realtime clock reads while paused, preserving normal host reads when unpaused. Answer a single relative zero-timeout clock subscription directly while paused; return
NOTSUPfor other paused polls. Keep the existing pause export and component import restrictions. The allocation-state getter is declared safe because its generated implementation only reads a nonshared global whose writers preserve valid enum values.The tests cover deterministic clock pause/resume, immediate-event contents for both clocks, and rejection of future timers while paused. A companion Go fixture exercises real GC during imported allocation. It fails with the released adapter, still fails at timer polling with only realtime caching fixed, and passes with both changes on Go 1.26.3 and 1.27.1.
Validation: release adapter build, strict adapter Clippy, formatting, and the sync/async adapter tests. The Go regression is tested separately with the built adapter.
This is deliberately limited to clock reads and a single immediate timer poll. It does not support arbitrary I/O during canonical allocation. The adapter's internal bootstrap-allocation branches are reviewed but not directly forced by these guest tests.
Related: #13563, #12112, https://github.com/bytecodealliance/componentize-go/issues/56, https://github.com/bytecodealliance/componentize-go/pull/60, and https://github.com/bytecodealliance/go-pkg/pull/7.
Fixes #14318.
Companion regression PR: https://github.com/bytecodealliance/componentize-go/pull/78 (tracked in https://github.com/bytecodealliance/componentize-go/issues/77).
carsonfarmer edited PR #14319:
Go GC can read wall time and poll timers during
cabi_realloc, where host calls are forbidden. Extend the pause added in #13563 to cache realtime reads and answer a single immediate timer poll without calling the host. Other paused polls returnNOTSUP.Adds clock and timer tests; the Go regression passes with the fix on Go 1.26.3 and 1.27.1.
Fixes #14318.
github-actions[bot] added the label wasi on PR #14319.
:thumbs_up: dicej submitted PR review:
Thanks, @carsonfarmer !
Like Alex mentioned on the previous PR, I don't love that we're bending over backwards to accommodate the Go runtime in an otherwise general-purpose tool, plus this tool was meant to be a temporary thing from the beginning, so it doesn't feel great to be adding new features to it. Eventually, I expect we'll want to move this kind of thing to
componentize-go, but for now this is probably the path of least resistance.
asteurer commented on PR #14319:
@dicej At what point would it make sense for us to move this adapter to componentize-go?
asteurer edited a comment on PR #14319:
@dicej Definitely open to hosting a custom adapter for componentize-go. At what point would it make sense for us to do this?
carsonfarmer commented on PR #14319:
I don't love that we're bending over backwards to accommodate the Go runtime in an otherwise general-purpose tool
Totally fair @dicej, I did try to avoid patching at the wasmtime layer, but couldn't find a cleaner solution. To be honest, there is a lot more clock reading in normal Go runtime than I would have imagined :face_with_diagonal_mouth:!
I have a working solution on my end, so there is no actual rush here for me. Happy to defer to a broader discussion about where something like this should ultimately live?
@ricochet pursued an alternative approach that would avoid any accommodations in the adapter.
carsonfarmer commented on PR #14319:
Nice!
dicej requested dicej for a review on PR #14319.
Last updated: Sep 20 2026 at 18:08 UTC