Skip to content

test(apps): a paused server process and a paused host each recover, and the host runs the lost process's onDisconnect (#973) - #998

Merged
davideast merged 3 commits into
mainfrom
test/host-closes-silent-consumer
Oct 16, 2026
Merged

davideast merged 3 commits into
mainfrom
test/host-closes-silent-consumer

Conversation

@davideast

@davideast davideast commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Adds the app scenario test/apps/host-closes-silent-consumer, the integration test for #973. It pauses a real node --import @pyric/cli/register process and then the real hosted dev server, and checks that the host runs the paused process's onDisconnect and that each side reconnects.

The scenario is slow (export const slow = true), so this PR's required App scenarios job (--skip-slow) does not run it. It runs in the Slow app scenarios workflow, triggered here by the ci-slow-scenarios label: https://github.com/davideast/pyric/actions/runs/38896696645

// test/apps/host-closes-silent-consumer/consumer.mjs, run as
//   node --import @pyric/cli/register consumer.mjs frozen http://127.0.0.1:<port>
import { remoteSandbox } from "@pyric/cli/remote";

const [name, url] = process.argv.slice(2);
const sandbox = remoteSandbox({ url });
const status = `status/${name}`;
await sandbox.rtdb.set(status, "online");
// The same worker-op the Kotlin, Swift and Flutter clients send; pyric-admin has no onDisconnect.
await sandbox.channel.op({ method: "rtdb.onDisconnectSet", path: status, value: "offline" });
sandbox.rtdb.onValue("messages/latest", (snapshot) => console.log(`${name} heard ${JSON.stringify(snapshot.value)}`));
console.log(`${name} online`);
// scenario.ts: the half-open socket is a paused process (SIGSTOP). The kernel keeps its
// loopback connection open, so the host sees no close, no FIN and no frames.
consumers.frozen.pause();
// host closes it after the 40s window (PYRIC_TEST_PEER_LIVENESS_MS); its onDisconnect runs
await readsWithin(page, 'status/frozen', 'offline', pausedAt, WINDOW_MS + 20_000);
// `running` heartbeats every 15s and stays online past the window

host.process.pause();
// `running` logs, while the host is still paused:
//   pyric: the remote sandbox sent nothing for 45s at http://127.0.0.1:<port>; the next op connects again, ...
host.process.resume();
// `running` reconnects and its listener hears the next write

Risk

  • The scenario takes about 2 minutes 10 seconds. It waits out a 40 s host window and the client's fixed 45 s liveness timeout, which no test knob shortens, so it is in the slow tier with host-closes-silent-page: pull requests skip it, and it runs on pushes to main, nightly, and on PRs labeled ci-slow-scenarios.
  • pause() uses SIGSTOP/SIGCONT on the process group, which only works on POSIX systems. Both app scenario workflows run on ubuntu.
  • AppProcess.stop() now sends SIGCONT before SIGTERM when the process is paused. A stopped process holds SIGTERM, so without this a failed step would leave a stopped process until the SIGKILL 5 s later. stop()'s unbounded wait after SIGKILL is test/apps driver: spawn fails with EBADF under concurrency, and AppProcess.stop() can then hang until the job timeout #997 and is unchanged here.

The host runs a lost server process's onDisconnect, and both sides reconnect

Step Before #996/#995 (76438dd) Now
Paused process's status/frozen stays online 60 s after the pause offline within the 40 s window
running (heartbeats) online online past window + one heartbeat
Resumed paused process n/a reports the loss, reconnects, listener hears a later write
Host paused running never notices running reports "sent nothing for 45s" while the host is paused, then reconnects after it resumes

The driver can pause a process and start one without waiting for it to exit

  • app.serverProcess(script, args, { env }) starts a node --import @pyric/cli/register process and returns its AppProcess immediately. It never waits on the process's exit; the scenario waits on its log with waitForLog, which has a timeout.
  • AppProcess.pause() / resume() signal the process group, and paused reports the state. The scenario resumes every process in a finally, and the run's teardown resumes a paused process before stopping it.

The ondisconnect-set-remove rows in rtdb-kotlin.ts, rtdb-swift.ts and rtdb-flutter.ts now name this scenario next to the host fixture. No count changes; conformance-model.test.ts passes.

Implementation notes

Closes #973

…nd the host runs the lost process's onDisconnect (#973)

Adds test/apps/host-closes-silent-consumer. Two long-lived
`node --import @pyric/cli/register` processes mark themselves online,
register onDisconnect().set('offline') over the remote handle's raw relay
channel (the same worker-op the Kotlin, Swift and Flutter clients send), and
keep an RTDB listener, against a real hosted dev server whose liveness window
is shortened to 40s.

SIGSTOP stands in for the half-open socket: the process stops, the kernel
keeps its loopback connection open, and the host sees no close, no FIN and
no frames, as from a process held at a breakpoint or an app the OS
suspended.

- Pausing one process: the host closes its socket after the window and its
  onDisconnect sets offline; the other process, which heartbeats, stays
  online past the window. Resumed, the paused process reports the loss,
  reconnects, and its listener hears a later write.
- Pausing the host: the running process reports "the remote sandbox sent
  nothing for 45s" while the host is still paused, then reconnects and hears
  a write once the host resumes.

The driver gains app.serverProcess(), which starts a register process
without waiting for it to exit, and AppProcess.pause()/resume(). stop()
continues a paused process before ending it, since a stopped process holds
SIGTERM, so a failed step never leaves a stopped process behind. The native
onDisconnect rows in the conformance registry name the scenario; no count
changes.

Run against 76438dd, main just after the ADR-0019 amendment and before
#996 and #995:

  bun test/apps/run.ts host-closes-silent-consumer
  step "the host closes the silent process, so its onDisconnect sets offline" failed
  AssertionError [ERR_ASSERTION]: the paused process was still online 60s after it was paused

  (part two alone, from a local copy without the part-one steps, since the
  failure above ends the run before part two)
  step "the host is paused, and the running process notices it stopped answering" failed
  Error: server process 2 (consumer.mjs) did not log /pyric: (.+) at http:\/\/127\.0\.0\.1:\d+; the next op connects again/ in time

Closes #973
It waits out a 40s host liveness window and the client's fixed 45s liveness
timeout, so pull requests skip it and the Slow app scenarios workflow runs it.
@davideast davideast added the ci-slow-scenarios Run the slow app scenarios (timer-bound) on this PR label Oct 16, 2026
@davideast
davideast merged commit 1618925 into main Oct 16, 2026
22 checks passed
@davideast
davideast deleted the test/host-closes-silent-consumer branch October 16, 2026 12:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci-slow-scenarios Run the slow app scenarios (timer-bound) on this PR

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native, remote admin, and in-page bridge clients send no heartbeat, so the host cannot tell when they vanish

1 participant