Merge pull request #2651 from vitorpamplona/claude/fix-windows-test-failure-dY1Jv
Fix race condition in MoQ subscription registration
This commit is contained in:
+10
-2
@@ -553,6 +553,16 @@ class MoqLiteSession internal constructor(
|
|||||||
MoqLiteControlType.Subscribe -> {
|
MoqLiteControlType.Subscribe -> {
|
||||||
val subPayload = buffer.readSizePrefixed() ?: return@collect
|
val subPayload = buffer.readSizePrefixed() ?: return@collect
|
||||||
val sub = MoqLiteCodec.decodeSubscribe(subPayload)
|
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(
|
bidi.write(
|
||||||
MoqLiteCodec.encodeSubscribeOk(
|
MoqLiteCodec.encodeSubscribeOk(
|
||||||
MoqLiteSubscribeOk(
|
MoqLiteSubscribeOk(
|
||||||
@@ -564,8 +574,6 @@ class MoqLiteSession internal constructor(
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
publisher.registerInboundSubscription(sub)
|
|
||||||
inboundSub = sub
|
|
||||||
dispatched = true
|
dispatched = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user