Commit 209ba11
authored
The perry-stdlib→perry-ext port (v0.5.572) dropped the
`js_stdlib_process_pending` call that the original
`crates/perry-stdlib/src/fastify/server.rs` had at the top of every
event-loop tick. As a result, any program combining `fastify` with
a perry-ext-* wrapper (ws, net, http, fetch) saw its listener
callbacks stranded the moment `app.listen()` entered its loop —
events accumulated on tokio workers but the JS main thread never
drained the per-wrapper queues. The user's hub reproduced this as
"`wss.on('connection', cb)` never fires" on v0.5.700–v0.5.892, filed
as #746; the underlying defect is in perry-ext-fastify, filed as
Three edits in `crates/perry-ext-fastify/src/server.rs`:
1. extern "C" block: declare `js_run_stdlib_pump` (defined in
`crates/perry-runtime/src/lib.rs:177`).
2. `event_loop`: call `js_run_stdlib_pump()` ahead of
`js_promise_run_microtasks()`, matching perry-stdlib's order.
3. `wait_for_promise`: same call inside the per-iteration body,
for parity with `crates/perry-stdlib/src/fastify/server.rs:432`
(defense-in-depth — the codegen-emitted `await` loop at
`crates/perry-codegen/src/expr.rs:9500` already pumps stdlib,
so this only matters for the rare case where a route handler
returns a Promise resolved by an external mechanism without an
inner `await` chain).
Validation:
- Fastify + WS combo before fix: `[wss listening]` + `[wss connection
fired]` never print; after fix: both fire on the next tick.
- Pure-WS minimal repro: already passed on macOS at HEAD (covered
by the codegen-emitted main event loop's existing pump call). The
combined fastify+ws path is what the hub actually exercises, so
this closes #746 in practice.
- Multi-await fastify handler (3× Promise.resolve + reply.code(201))
returns correct JSON in 4 ms.
- Multi-await perry-ext-bcrypt chain (2× hash + 1× compare inside a
POST handler) returns correct JSON in 4 ms.
- `cargo test --release -p perry-ext-fastify`: 10 passed.
- `cargo test --release --workspace --exclude perry-ui-{ios,tvos,
watchos,visionos,android,windows,gtk4}`: exit 0.
wait_for_promise omission caused @perryts/mysql's `await
pool.exec(...)` chain to stall after the first INSERT, but a
perry-ext-bcrypt chain (same shape, same queue_promise_resolution
mechanism) works fine without the wait_for_promise pump — the
codegen-emitted await loop pumps stdlib on every iteration, so
inner awaits don't strand. The actual #748 root cause needs
reproduction with a real @perryts/mysql + MySQL setup and is left
open.
Closes #747.
Closes #746 (for the realistic fastify+ws use case; the pure-WS-only
Linux symptom from the minimal repro doesn't reproduce on macOS at
HEAD — left as a Linux follow-up if it persists).
Refs #748 (investigated but not closed; see CHANGELOG for full
context).
1 parent b2cea69 commit 209ba11
5 files changed
Lines changed: 101 additions & 72 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | | - | |
| 11 | + | |
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| |||
0 commit comments