Prevent accumulation of subscription notifications when the last AsyncIterator
falls out of scope
#3090
Labels
bug
Something isn't working
Overview
There's something about the chain of
AsyncGenerators
in the subscriptions transport that results in orphanedAsyncIterators
stuffing messages intoqueuedMessages
all day long until you run out of memory.AsyncIterator
and you stop iterating over it, an inner iterator won't learn of that fact; it will keep pumping notifications intoqueuedMessages
forever.Steps to reproduce
Instrument around here where messages are added to
queuedMessages
and watch as the number of messages destined for theAsyncIterator
in(A)
grows forever.Description of bug
Right now the
AsyncIterable
returned bysubscribe()
offers certain guarantees about message delivery that we might have to reevaluate. In particular, it guarantees that if there's a delay between having processed a value and the time you ask theAsyncIterator
for the next value, any subscription notifications received during that time will be queued and delivered to you all at once. If you never ask for the next value and you never abort the subscription (unsubscribe) then this queue grows forever.We might need to eliminate this guarantee. Alternatively, maybe this is one of those rare use cases for
FinalizationRegistry
, if only the thing that's doing the queueing can know when the thing consuming the messages has fallen out of scope.The text was updated successfully, but these errors were encountered: