Skip to content

fix(datastore): Use a UnicastSubject instead of a ReplaySubject #2353

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
import io.reactivex.rxjava3.core.Observable;
import io.reactivex.rxjava3.disposables.CompositeDisposable;
import io.reactivex.rxjava3.schedulers.Schedulers;
import io.reactivex.rxjava3.subjects.ReplaySubject;
import io.reactivex.rxjava3.subjects.UnicastSubject;

/**
* Observes mutations occurring on a remote {@link AppSync} system. The mutations arrive
Expand All @@ -78,7 +78,7 @@ final class SubscriptionProcessor {
private final Consumer<Throwable> onFailure;
private final CompositeDisposable ongoingOperationsDisposable;
private final long adjustedTimeoutSeconds;
private ReplaySubject<SubscriptionEvent<? extends Model>> buffer;
private UnicastSubject<SubscriptionEvent<? extends Model>> buffer;

/**
* Constructs a new SubscriptionProcessor.
Expand Down Expand Up @@ -123,8 +123,8 @@ synchronized void startSubscriptions() throws DataStoreException {
AbortableCountDownLatch<DataStoreException> latch = new AbortableCountDownLatch<>(subscriptionCount);

// Need to create a new buffer so we can properly handle retries and stop/start scenarios.
// Re-using the same buffer has some unexpected results due to the replay aspect of the subject.
buffer = ReplaySubject.create();
// Re-using the same buffer has some unexpected results due to the queueing aspect of the subject.
buffer = UnicastSubject.create();

Set<Observable<SubscriptionEvent<? extends Model>>> subscriptions = new HashSet<>();
for (ModelSchema modelSchema : modelProvider.modelSchemas().values()) {
Expand Down