Skip to content
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

ManyToOneConcurrentArrayQueue poll may return null when queue isEmpty() is false #269

Closed
wireknight opened this issue Nov 26, 2022 · 1 comment

Comments

@wireknight
Copy link

To my understanding from the javadoc, poll() should be consistent with isEmpty() return value and thus should never return null is if isEmpty returns false. Using the snippet below I observed a different behaviour

import java.io.Serializable;
import java.util.Objects;
import org.agrona.concurrent.ManyToOneConcurrentArrayQueue;
import java.util.concurrent.ForkJoinPool;
import java.util.concurrent.atomic.AtomicBoolean;

public class AgroTest {
    public static void main(String[] args) {
        ManyToOneConcurrentArrayQueue<TestMsg> queue = new ManyToOneConcurrentArrayQueue<>(1000);
        AtomicBoolean finished = new AtomicBoolean(false);
        long msgsToSend = 1_000_000_000;
        ForkJoinPool.commonPool().execute(() -> {
            TestMsg payload = new TestMsg("TestMe", new Payload(0xdeadbeef));
            for (long element = 0; element < msgsToSend; element++) {
                queue.offer(payload);
            }
            finished.setRelease(true);
        });
        while(!finished.getAcquire() || !queue.isEmpty()) {
            while(!queue.isEmpty()) {
                Objects.requireNonNull(queue.poll());
            }
        }
    }
    private record Payload(int value) implements Serializable {}
    private record TestMsg(String name, Payload payload) implements Serializable {}
}

Output:

Exception in thread "main" java.lang.NullPointerException
	at java.base/java.util.Objects.requireNonNull(Objects.java:208)
	at io.reacted.examples.benchmarking.AgroTest.main(AgroTest.java:34)
@mjpt777
Copy link
Contributor

mjpt777 commented Nov 27, 2022

Duplicate of #216

@mjpt777 mjpt777 marked this as a duplicate of #216 Nov 27, 2022
@mjpt777 mjpt777 closed this as not planned Won't fix, can't repro, duplicate, stale Nov 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants