cloudflare / cloudflare/wasm-coredump

Use for queue and scheduled not supported

Open
#3 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
46
Forks
6
PR merge metrics
No merged PRs in 30d

Description

Working on trying to identify what causes a `memory access out of bounds CompileError` in some queue handlers - see https://github.com/cloudflare/workers-rs/issues/374 - I stumbled upon the fact that I can't use `recordCoredump` for workers that handle queue events or cron triggers, since they lack a `request` object.

My `entry.mjs` file looks as follows:

```javascript
import shim, { getMemory, wasmModule } from "../build/worker/shim.mjs"
import { recordCoredump } from "@cloudflare/wasm-coredump"

const timeoutSecs = 60;

async function fetch(request, env, ctx) {
try {
// see https://github.com/rustwasm/wasm-bindgen/issues/2724.
return await Promise.race([
shim.fetch(request, env, ctx),
new Promise((r, e) => setTimeout(() => e("timeout"), timeoutSecs * 1000))
]);
} catch (err) {
console.error(err);
const memory = getMemory();
const coredumpService = env.COREDUMP_SERVICE;
await recordCoredump({ memory, wasmModule, request, coredumpService });
throw err;
}
}

async function queue(batch, env, ctx) {
try {
// see https://github.com/rustwasm/wasm-bindgen/issues/2724.
return await Promise.race([
shim.queue(batch, env, ctx),
new Promise((r, e) => setTimeout(() => e("timeout"), timeoutSecs * 1000))
]);
} catch (err) {
console.error(err);
const memory = getMemory();
const coredumpService = env.COREDUMP_SERVICE;
await recordCoredump({ memory, wasmModule, request, coredumpService });
throw err;
}
}

async function scheduled(event, env, ctx) {
try {
// see https://github.com/rustwasm/wasm-bindgen/issues/2724.
return await Promise.race([
shim.scheduled(event, env, ctx),
new Promise((r, e) => setTimeout(() => e("timeout"), timeoutSecs * 1000))
]);
} catch (err) {
console.error(err);
const memory = getMemory();
const coredumpService = env.COREDUMP_SERVICE;
await recordCoredump({ memory, wasmModule, request, coredumpService });
throw err;
}
}

export default { fetch, queue, scheduled };
```

However the calls to `recordCoredump` from `queue` and `scheduled` fail with exception:

```
"exceptions": [
{
"name": "ReferenceError",
"message": "request is not defined",
"timestamp": 1693489675116
}
],
```

It would be nice if the `request` parameter was made optional and handled without error if it's not passed, so that I can perform core dumps for cron triggers and queue consumers.

Contributor guide

Open the contributing guide

Research direction

Start with the queue and scheduled handlers in entry.mjs and compare their recordCoredump calls with the fetch handler. Trace how recordCoredump handles its request argument, then verify that queue and cron failures can produce a coredump without a request object.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, wasm
Domain
backend, observability
Issue type
Feature
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.