-
Notifications
You must be signed in to change notification settings - Fork 7.6k
buffer() using TimeBasedChunks results in duplicates being sent onNext #429
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
Comments
I think this is not a bug. I suppose you want to do something like this: create a chunk --> sleep 100ms --> emit the chunk -> create a new chunk However, as create a chunk --> sleep 100ms --> create a new chunk -> emit the old chunk So before the old chunk is emited, the old and new chunks will both receive any results after I think this is not a bug because |
What's the status of this being a bug or not? @headinthebox Can you confirm? |
If I change With
With that I see this:
That is not expected, so I tend to agree that we have a bug. The second buffer starting at |
And if you change it to .buffer(42, TimeUnit.MICROSECONDS), then some items will be dropped. see also #756
+1 |
This bug should be resolved in the latest release. |
This test now passes: @Test
public void testDuplicate() throws Exception {
final Set<Integer> unique = new HashSet<Integer>();
Observable.create(new OnSubscribe<Integer>() {
@Override
public void call(final Subscriber<? super Integer> t1) {
final Future<?> t = Executors.newSingleThreadExecutor().submit(new Runnable() {
@Override
public void run() {
int count = 0;
for (int i = 0; i < 11; i++) {
t1.onNext(count++);
try {
Thread.sleep(10);
} catch (InterruptedException e) {
}
}
}
});
t1.add(Subscriptions.from(t));
}
})
.buffer(100, 100, TimeUnit.MILLISECONDS)
.subscribe(new Action1<List<Integer>>() {
@Override
public void call(List<Integer> t1) {
if (t1.isEmpty())
return;
System.out.println(t1.toString());
for (Integer i : t1) {
synchronized (unique) {
if (unique.contains(i)) {
System.out.println("Duplicate for " + i);
}
Assert.assertFalse(unique.contains(i));
unique.add(i);
}
}
}
});
Thread.sleep(10000);
} It emits:
|
This seems to be isolated to the first chunk.
The text was updated successfully, but these errors were encountered: