fix(worker): ReadBulk never tears down a caller's item or subscription (#238)
ReadBulk sent every advised-but-uncached and added-but-not-advised tag down the snapshot path. MXAccess returns the caller's existing handle for a re-added address, so the snapshot's AddItem/Advise ran on the caller's own item and the symmetric teardown then UnAdvised and RemoveItem'd it: the subscription delivered one value and went silent. Teardown is now ownership-scoped: it unadvises only advices the read's own Advise created and removes only items the read's own AddItem created. A tag the session already holds is read through the caller's handle with no AddItem: advised-but-uncached waits on the existing subscription with no COM call; added-but-not-advised is advised for the read and unadvised afterwards (back to its prior state), never removed. A snapshot AddItem that returns a handle the registry already tracks (differently spelled address) is treated as the caller's item and never removed. Adds MxAccessSessionTests regressions; updates gateway.md, Contracts, DesignDecisions, MxAccessWorkerInstanceDesign.
This commit is contained in:
+23
-6
@@ -532,7 +532,21 @@ choices were considered:
|
||||
(`was_cached = true`). Otherwise it takes the full `AddItem + Advise +
|
||||
wait-for-first-OnDataChange + UnAdvise + RemoveItem` lifecycle itself
|
||||
(`was_cached = false`) and leaves the session exactly as it was before
|
||||
the call. The cache lives on a per-session `MxAccessValueCache`,
|
||||
the call. "Exactly as it was" is enforced by ownership, not by
|
||||
symmetry: teardown undoes only the `AddItem` and `Advise` calls the read
|
||||
itself made. A tag the session already holds is read through the
|
||||
caller's item handle with no `AddItem` — an advised tag whose first
|
||||
`OnDataChange` is not cached yet is waited on through the caller's
|
||||
subscription, and an added-but-not-advised tag is advised for the read
|
||||
and unadvised afterwards, which returns it to the caller's prior state;
|
||||
neither is ever removed. Re-adding the caller's address instead returns
|
||||
the caller's own handle from MXAccess, and the old symmetric teardown
|
||||
then unadvised and removed the caller's item — a subscription that
|
||||
delivered one value and went silent (#238). A snapshot `AddItem` that
|
||||
still returns a handle the registry already tracks (an address spelled
|
||||
differently from the caller's) is never removed either; at worst that
|
||||
leaves one extra `AddItem` reference until the caller removes the item
|
||||
or unregisters, which is preferable to deleting a live subscription. The cache lives on a per-session `MxAccessValueCache`,
|
||||
populated by `MxAccessBaseEventSink` on every `OnDataChange` after the
|
||||
event clears the outbound queue.
|
||||
|
||||
@@ -543,12 +557,15 @@ choices were considered:
|
||||
|
||||
The chosen behavior matches what callers actually want from "current
|
||||
value" — a free read of an already-streaming tag, and a one-shot snapshot
|
||||
otherwise — and never disturbs subscriptions the caller did not create.
|
||||
otherwise — and never disturbs subscriptions the caller already holds.
|
||||
The decision intentionally does NOT synthesize an `OnDataChange` event
|
||||
from the snapshot path: the snapshot value reaches the caller through
|
||||
`ReadBulk`'s reply payload only, not through the event stream. This
|
||||
preserves the "Don't synthesize events" rule that scopes the rest of the
|
||||
worker.
|
||||
from the snapshot path: the worker adds no event of its own for the
|
||||
snapshot value, which reaches the caller through `ReadBulk`'s reply
|
||||
payload. The native `OnDataChange` MXAccess raises for a handle the read
|
||||
advised still flows through the event sink like any other — including,
|
||||
for an added-but-not-advised caller item, under the caller's own item
|
||||
handle while the read holds it advised. This preserves the "Don't
|
||||
synthesize events" rule that scopes the rest of the worker.
|
||||
|
||||
`ReadBulk`'s wait loop pumps Windows messages on the worker STA
|
||||
(`StaRuntime.PumpPendingMessages`) on every poll iteration so the inbound
|
||||
|
||||
Reference in New Issue
Block a user