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

Size of queue may more then max size +1 #216

Closed
yiYangGit opened this issue Aug 27, 2018 · 4 comments
Closed

Size of queue may more then max size +1 #216

yiYangGit opened this issue Aug 27, 2018 · 4 comments

Comments

@yiYangGit
Copy link

I found a bug earlier this year

Seems to be

spscArrayGrowableQueue

init give the max size

but can run code make the queue = max +1

i truly run test code find it ,it is existence
in Special cases

@nitsanw
Copy link
Contributor

nitsanw commented Aug 28, 2018

Can you be more specific? give a test case?

@yiYangGit
Copy link
Author

import org.jctools.queues.SpscGrowableArrayQueue;

/**

  • Created by yangyi438 on 2018/9/2.
    */
    public class TestError2 {
    public static void main(String[] args) {
    int q = 0;
    SpscGrowableArrayQueue queue = new SpscGrowableArrayQueue(8, 32);
    for (int i = 0; i < 33; i++) {
    queue.offer(q++);
    }
    for (int i = 0; i < 7; i++) {
    Integer poll = queue.poll();
    }
    for (int i = 0; i < 14; i++) {
    Integer poll = queue.poll();
    }
    for (int i = 0; i < 80; i++) {
    queue.offer(q++);
    }
    int counot = 0;
    while (true) {
    Integer poll = queue.poll();
    if (poll != null) {
    counot++;
    } else {
    break;

         }
     }
     if (counot > 32) {
         throw new Error();
     }
    

    }
    }

this code is

    <dependency>
        <groupId>org.jctools</groupId>
        <artifactId>jctools-core</artifactId>
        <version>2.1.2</version>
    </dependency>

I debug carefully for reasons
It looks like index is the wrong calculation
There will be a value of null in the array
I forgot the exact reason. It's been months since I found out
You can debug see detail and fix it

@nitsanw
Copy link
Contributor

nitsanw commented Sep 6, 2018

Thanks for the test case, and sorry for the long silence.
I have reproduced the issue and working on a solution but have been very busy.

@yiYangGit
Copy link
Author

Jctools is the best concurrency library and we admire you and appreciate your contributions in your busy schedule

franz1981 added a commit to franz1981/JCTools that referenced this issue Sep 7, 2018
…acity

Adjust producer limit in order to allow one more element to be added
in place of the unneeded JUMP when the max capacity producer buffer
has been allocated
nitsanw added a commit that referenced this issue Sep 20, 2018
Fixes #216: Size of SpscGrowableArrayQueue can exceeds max capacity
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