Skip to content

feat: GC finalization for preview2-shims#357

Merged
guybedford merged 4 commits intomainfrom
finalize
Jan 25, 2024
Merged

feat: GC finalization for preview2-shims#357
guybedford merged 4 commits intomainfrom
finalize

Conversation

@guybedford
Copy link
Collaborator

@guybedford guybedford commented Jan 25, 2024

This resolves the GC integration for the JS preview2-shims bindings, where if a Symbol.dispose call is not done for any resource, the GC will always kick in and handle the resource finalization in this case.

This is typically only for invalid components, but also affects direct usage of the preview2 APIs from JS where manual Symbol.dispose calls are forgotten to be called by a consumer.

One complexity here is that when the GC runs, it can dispose parent resources before their children. To avoid this, we create a strong reference in the finalizer for any child resource to its parent resource, so that this is not possible by the semantics of the GC itself. Thanks to @alexcrichton for suggesting the approach to this problem here. GC tests are included in the preview2 unit tests using the --expose-gc option in Node.js, verifying the GC integration, and that these ordering bugs are avoided.

Resolves #335.

@guybedford guybedford merged commit cb80dfa into main Jan 25, 2024
@guybedford guybedford deleted the finalize branch January 25, 2024 06:27
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.

jco hangs on 12_05 wasi:http component from tinygo that wasmtime/spin run no problem

1 participant