fix(nestsClient): register inbound moq-lite subscription before sending Ok

The publisher's inbound-bidi handler wrote SubscribeOk to the bidi
before calling registerInboundSubscription. The peer's first
publisher.send() after observing Ok could race the registration on
dispatchers that resume the peer's continuation before the handler's
(notably Windows under Dispatchers.Default), causing send to observe
an empty inboundSubs and return false. Reordering makes the peer's
view of Ok a happens-after of the registration.

Fixes the Windows-only failure in
MoqLiteSessionTest.publisher_acks_subscribe_and_pushes_group_data_on_uni_stream.
This commit is contained in:
Claude
2026-04-29 22:14:23 +00:00
parent f63e3b1c67
commit 19b534a9e2
@@ -553,6 +553,16 @@ class MoqLiteSession internal constructor(
MoqLiteControlType.Subscribe -> {
val subPayload = buffer.readSizePrefixed() ?: return@collect
val sub = MoqLiteCodec.decodeSubscribe(subPayload)
// Register the subscription BEFORE sending Ok so the
// peer's observation of Ok is a happens-after of
// `inboundSubs += sub`. Otherwise on dispatchers that
// resume the peer's `bidi.incoming().first()`
// continuation before this coroutine's continuation
// (notably Windows under Dispatchers.Default), the
// peer's first `publisher.send` after Ok races the
// registration and observes an empty subscriber set.
publisher.registerInboundSubscription(sub)
inboundSub = sub
bidi.write(
MoqLiteCodec.encodeSubscribeOk(
MoqLiteSubscribeOk(
@@ -564,8 +574,6 @@ class MoqLiteSession internal constructor(
),
),
)
publisher.registerInboundSubscription(sub)
inboundSub = sub
dispatched = true
}