Repository navigation
fix(store-inmemory): deliver events appended before a new subscription runs - #420
Merged
Merged
Conversation
…n runs The in-memory store's subscribe and subscribeAll built their streams on Stream.fromPubSub, which only subscribes to the PubSub once the stream runs. An event appended after subscribe returned but before the stream started was published to nobody. Per-stream subscribe also took its history snapshot at subscribe time, so an event appended in that gap was in neither the snapshot nor the live feed. A live stream now takes its snapshot and subscribes to the PubSub when it runs, both under the lock that append holds while it publishes. The snapshot starts from the position recorded when subscribe was called, so nothing is lost or delivered twice, and a stream that is never run holds no subscription. The new tests subscribe, append, and only then run the stream. The fork-based tests added to the Postgres store pass against the old in-memory code, because the forked fiber subscribes before the append publishes.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



The in-memory store lost an event appended after
subscribeorsubscribeAllreturned but before the returned stream started running. The Postgres store had the same gap, fixed in #399.The cause was
Stream.fromPubSub, which subscribes to the PubSub only when the stream runs. Per-streamsubscribealso took its history snapshot at subscribe time, so an event appended in the gap was in neither the snapshot nor the live feed.A live stream now takes its snapshot and subscribes to the PubSub when it runs, both under the lock that
appendholds while it publishes. The snapshot starts from the position recorded whensubscribewas called.EventStore.subscribetakes noScope, so subscribing eagerly would leave a subscription open for any stream the caller never runs. Doing the work at run time avoids that without changing the public API.The new tests subscribe, append, and only then run the stream. The fork-based tests added to the Postgres store in #399 pass against the old in-memory code, because the forked fiber subscribes before the append publishes.