Fix three test bugs found by the first Linux verify run

P8's test opened a fresh reliable stream on the first send, so disposing
before its microtask ran hit streamOpen() against an already-shut-down
connection (its own native error) instead of ever reaching sendOnStream's
disposed guard. Prime the stream with an awaited first send so the second,
raced send chains straight onto sendOnStream with no streamOpen call in
between.

P10b's test registered connection A's and B's server-side listeners after
an `await`, the exact async-registration gap fix 1 exists to close: a
connection's next native event can be dispatched, and silently dropped
(no listener registered yet), before that await's continuation runs.
Register both listeners synchronously inside their LISTENER_NEW_CONNECTION
callback instead.

The IPv6 fix 3 test asserted the wrong expectation: WHATWG URL's own
`hostname` keeps the brackets for an IPv6 literal, so the round trip
through parseQuicRealtimeEndpoint correctly returns "[::1]", not "::1".

Confirmed via a Linux verify run (cultlib-quic-native-dev image): before
this commit, exactly these three new tests failed and every other test
(155) passed, including every other fix/P3 test added alongside them.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-09-23 19:19:38 +02:00
commit 329a78c255
3 changed files with 58 additions and 34 deletions

View file

@ -1034,17 +1034,29 @@ test("P8: a reliable send still queued behind reliableSendTail rejects instead o
};
const connector = new CultMeshQuicRealtimeConnector();
const transport = await connector.connect(candidate, target);
// `sendFrame` chains onto `reliableSendTail`, which resolves as a
// microtask; calling `dispose()` synchronously right after, in the same
// turn, guarantees `cleanup()` has already set `disposed = true` by the
// time that microtask runs `sendOnStream`. Without the `this.disposed`
// guard `sendOnStream` registers (P8's target), this send would sit in
// `pendingSends` forever: `cleanup()`'s reject sweep already ran once
// before this send was ever registered, and no later native event can
// reach it either, since `offConnectionEvent` already ran too.
const send = transport.sendFrame(testFrame({ delivery: "reliable-ordered" }));
transport.dispose();
await assert.rejects(send, /disposed/i);
try {
// Prime the reliable outbound stream and let it fully settle, so its
// id is already cached: a second reliable send then chains straight
// onto `sendOnStream` with no `streamOpen` call of its own in between
// (a `streamOpen` against an already-shut-down connection fails with
// its own native error, which would mask the guard this test targets).
await transport.sendFrame(testFrame({ delivery: "reliable-ordered", sequence: 1n }));
// `sendFrame` chains onto `reliableSendTail`, which resolves as a
// microtask; calling `dispose()` synchronously right after, in the
// same turn, guarantees `cleanup()` has already set `disposed = true`
// by the time that microtask runs `sendOnStream`. Without the
// `this.disposed` guard `sendOnStream` registers (P8's target), this
// send would sit in `pendingSends` forever: `cleanup()`'s reject sweep
// already ran once before this send was ever registered, and no later
// native event can reach it either, since `offConnectionEvent` already
// ran too.
const send = transport.sendFrame(testFrame({ delivery: "reliable-ordered", sequence: 2n }));
transport.dispose();
await assert.rejects(send, /disposed/i);
} finally {
transport.dispose();
}
} finally {
await listener.close();
}

View file

@ -198,9 +198,28 @@ test(
// `onFault` (P10b's target), that throw would escape the pump's
// dispatch loop and take every other connection down with it instead
// of staying scoped to connection A.
const acceptedA = waitFor<bigint>((resolve) => {
//
// The server-side connection listener is registered synchronously,
// inside the LISTENER_NEW_CONNECTION callback itself, rather than
// after an `await`: the native bridge can dispatch a connection's next
// event (CERTIFICATE_RECEIVED, or CONNECTED) before a later `await`'s
// continuation ever runs, and an event with no listener registered for
// its connection id is silently dropped (`dispatch`'s own
// `if (!entry) return`) — the same async-registration gap fix 1 closed
// for the provider's own accept path.
const serverAFaulted = waitFor<void>((resolve) => {
runtime.onListenerEvent(listenerId, (event) => {
if (event.type === CULTMESH_QUIC_EVENT_LISTENER_NEW_CONNECTION) resolve(event.connectionId);
if (event.type !== CULTMESH_QUIC_EVENT_LISTENER_NEW_CONNECTION) return;
runtime.onConnectionEvent(
event.connectionId,
() => {
throw new Error("P10b: connection A's listener always throws.");
},
() => {
resolve();
throw new Error("P10b: connection A's onFault also throws.");
},
);
});
});
const clientA = runtime.connectionOpen("127.0.0.1", boundPort);
@ -209,24 +228,18 @@ test(
runtime.connectionCertificateComplete(clientA, true);
}
});
const serverAId = await acceptedA;
runtime.onConnectionEvent(
serverAId,
() => {
throw new Error("P10b: connection A's listener always throws.");
},
() => {
throw new Error("P10b: connection A's onFault also throws.");
},
);
// Give A's handshake a moment to reach the throwing listener and fault.
await new Promise((resolve) => setTimeout(resolve, 300));
await serverAFaulted;
// Connection B, opened only after A faulted: if the throw above ever
// escaped the pump, this connection would never reach CONNECTED at all.
const acceptedB = waitFor<bigint>((resolve) => {
let serverBConnected = false;
const serverBAccepted = waitFor<void>((resolve) => {
runtime.onListenerEvent(listenerId, (event) => {
if (event.type === CULTMESH_QUIC_EVENT_LISTENER_NEW_CONNECTION) resolve(event.connectionId);
if (event.type !== CULTMESH_QUIC_EVENT_LISTENER_NEW_CONNECTION) return;
runtime.onConnectionEvent(event.connectionId, (connectionEvent) => {
if (connectionEvent.type === CULTMESH_QUIC_EVENT_CONNECTION_CONNECTED) serverBConnected = true;
});
resolve();
});
});
const clientB = runtime.connectionOpen("127.0.0.1", boundPort);
@ -239,17 +252,12 @@ test(
if (event.type === CULTMESH_QUIC_EVENT_CONNECTION_CONNECTED) resolve();
});
});
const serverBId = await acceptedB;
let serverBConnected = false;
runtime.onConnectionEvent(serverBId, (event) => {
if (event.type === CULTMESH_QUIC_EVENT_CONNECTION_CONNECTED) serverBConnected = true;
});
await serverBAccepted;
await clientBConnected;
assert.ok(serverBConnected, "connection B's handler must still run after A's onFault threw");
runtime.connectionShutdown(clientA, 0n);
runtime.connectionShutdown(clientB, 0n);
runtime.connectionShutdown(serverBId, 0n);
runtime.listenerClose(listenerId);
} finally {
await runtime.release();

View file

@ -661,8 +661,12 @@ test("fix 3: an IPv6 bind advertises a bracketed literal that round-trips throug
provider.advertisedEndpoint,
/^cultmesh-state\+quic:\/\/\[::1\]:\d+\?cert-sha256=[0-9A-F]{64}$/,
);
// `URL`'s own `hostname` keeps the brackets for an IPv6 literal (unlike
// the unbracketed form `formatEndpointHost` accepted as input); the
// round trip's job is proving the endpoint parses at all, not stripping
// brackets the WHATWG URL parser itself never strips.
const parsed = parseQuicRealtimeEndpoint(provider.advertisedEndpoint);
assert.equal(parsed.host, "::1");
assert.equal(parsed.host, "[::1]");
} finally {
provider.dispose();
}