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

Commands with same priority are not handled in the correct order #2257

Closed
MGathier opened this issue Jun 17, 2022 · 1 comment
Closed

Commands with same priority are not handled in the correct order #2257

MGathier opened this issue Jun 17, 2022 · 1 comment
Assignees
Labels
Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: Resolved Use to signal that work on this issue is done. Type: Bug Use to signal issues that describe a bug within the system.

Comments

@MGathier
Copy link
Member

MGathier commented Jun 17, 2022

Basic information

  • Axon Framework version: 4.5.8
  • JDK version: 11
  • Complete executable reproducer if available (e.g. GitHub Repo):

Steps to reproduce

AxonServerCommandBus is using a PriorityBlockingQueue to queue commands to execute. When the priority of 2 items is the same,
this queue does not respect the order in which they are queued. A simple testcase for this:

@Test
    public void blockingQueueTest() throws InterruptedException {
        PriorityBlockingQueue<SimpleMessage> priorityBlockingQueue = new PriorityBlockingQueue<SimpleMessage>();
        priorityBlockingQueue.put(new SimpleMessage(0, "1"));
        priorityBlockingQueue.put(new SimpleMessage(0, "2"));
        priorityBlockingQueue.put(new SimpleMessage(0, "3"));
        priorityBlockingQueue.put(new SimpleMessage(0, "4"));
        priorityBlockingQueue.put(new SimpleMessage(0, "5"));
        priorityBlockingQueue.put(new SimpleMessage(0, "6"));

        assertEquals("1", priorityBlockingQueue.take().data);
        assertEquals("2", priorityBlockingQueue.take().data);
        assertEquals("3", priorityBlockingQueue.take().data);
        assertEquals("4", priorityBlockingQueue.take().data);
        assertEquals("5", priorityBlockingQueue.take().data);
        assertEquals("6", priorityBlockingQueue.take().data);
    }
    
    private class SimpleMessage implements Comparable<SimpleMessage>{
        private final long priority;
        private final String data;

        private SimpleMessage(long priority, String data) {
            this.priority = priority;
            this.data = data;
        }

        @Override
        public int compareTo(@NotNull SimpleMessage o) {
            return Long.compare(priority, o.priority);
        }
    }

With high volumes of commands, this could lead to starvation. An older command remains in the queue for a long time as the newer commands are picked up first.

Expected behaviour

When commands with the same priority are queued, I expect that the first command will be taken first.

Actual behaviour

Order in which they are taken is random.

@MGathier MGathier added the Type: Bug Use to signal issues that describe a bug within the system. label Jun 17, 2022
@smcvb smcvb added Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: In Progress Use to signal this issue is actively worked on. labels Jun 17, 2022
@smcvb smcvb self-assigned this Jun 17, 2022
@smcvb smcvb added Status: Under Discussion Use to signal that the issue in question is being discussed. Status: In Progress Use to signal this issue is actively worked on. and removed Status: In Progress Use to signal this issue is actively worked on. Status: Under Discussion Use to signal that the issue in question is being discussed. labels Jun 17, 2022
@smcvb smcvb added this to the Release 4.5.12 milestone Jun 23, 2022
@smcvb
Copy link
Member

smcvb commented Jun 24, 2022

Closing this issue as it's resolved in pull request #2263.

@smcvb smcvb closed this as completed Jun 24, 2022
@smcvb smcvb added Status: Resolved Use to signal that work on this issue is done. and removed Status: In Progress Use to signal this issue is actively worked on. labels Jun 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Priority 1: Must Highest priority. A release cannot be made if this issue isn’t resolved. Status: Resolved Use to signal that work on this issue is done. Type: Bug Use to signal issues that describe a bug within the system.
Projects
None yet
Development

No branches or pull requests

3 participants