cloudflare / cloudflare/workerd

🐛 Bug Report — Runtime APIs: large wasm memory allocations bring a DurableObject into broken state

Open
#3,264 15 comments 2 reactions 0 assignees View on GitHub
Dominant language
C++
Stars
8.7k
Forks
739
Avg merge
2d 20h
Merged PRs (30d)
174

Description

### Details

[Reproduction code](https://github.com/yarolegovich/cf-automerge-overload) with steps in README.

We're using [automerge](https://github.com/automerge/automerge) library. When we make a large number of allocations a:

> Range Error: Invalid typed array length: undefined

Error is thrown in this code produced by wasm-bindgen:

```ts
let cachedUint8ArrayMemory0 = null;

function getUint8ArrayMemory0() {
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
}
return cachedUint8ArrayMemory0;
}
```

`wasm.memory.buffer` is an `ArrayBuffer` with non-zero byteLength.

The worts part is that after this happens for the first time the object starts failing on any interaction with the library (cause of memory access attempts) and it is hard to get the object out of this state. DurableObject reset by an unhandled exception or `this.ctx.abort()` doesn't help. Other DurableObjects of the same type are working fine (until overloaded).

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.