Skip to content

fix: prevent WASM out-of-bounds trap in concurrent generate calls#111

Merged
viviveevee merged 2 commits intodfinity:mainfrom
q-uint:fix/invalid-byte-sequence-service-ts
Feb 18, 2026
Merged

fix: prevent WASM out-of-bounds trap in concurrent generate calls#111
viviveevee merged 2 commits intodfinity:mainfrom
q-uint:fix/invalid-byte-sequence-service-ts

Conversation

@q-uint
Copy link
Copy Markdown
Contributor

@q-uint q-uint commented Feb 18, 2026

When multiple icpBindgen plugin instances run concurrently (e.g. several .did files processed during Vite's buildStart), the WASM GenerateResult object could be held across await boundaries in writeBindings(). This was observed to cause intermittent "Out of bounds memory access" traps on the service_ts getter.

Extract all strings from the WASM object synchronously immediately after wasmGenerate() and free it explicitly, so that writeBindings operates only on plain JS strings.

Ref: #109

…inity#109)

When multiple icpBindgen plugin instances run concurrently (e.g.
several .did files processed during Vite's buildStart), the WASM
GenerateResult object could be held across await boundaries in
writeBindings(). This was observed to cause intermittent "Out of
bounds memory access" traps on the service_ts getter.

Extract all strings from the WASM object synchronously immediately
after wasmGenerate() and free it explicitly, so that writeBindings
operates only on plain JS strings.
@q-uint
Copy link
Copy Markdown
Contributor Author

q-uint commented Feb 18, 2026

Verified: tested locally against a Vite project with 6 concurrent icpBindgen plugin instances. The build now passes reliably (previously failed consistently with Out of bounds memory access). Since the root cause is a concurrency race condition in WASM object lifetimes across await boundaries, this would be difficult to cover with unit tests.

@q-uint q-uint marked this pull request as ready for review February 18, 2026 10:56
@q-uint q-uint requested a review from a team as a code owner February 18, 2026 10:56
Copy link
Copy Markdown
Contributor

@viviveevee viviveevee left a comment

Choose a reason for hiding this comment

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

Excellent work, thank you!

@viviveevee viviveevee merged commit a57caa3 into dfinity:main Feb 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants