Sending multiple commands to the same aggregate at the same time

Hi, I have a strange effect I can’t my head around.
I’m using the open source version 4.3 of axon server.
Every time more than one command is sent to the same aggregate, none of the commands is processed, the call “commandGateway.sendAndWait (command)” wait forever respectively “commandGateway.sendAndWait(command, 10, TimeUnit.SECONDS)” times out, and from there on no command for that aggregate is processed anymore.
After restarting the axon server all is fine.

Maybe it is important to know the command handler of the aggregate uses @CreationPolicy(AggregateCreationPolicy.CREATE_IF_MISSING).

Is this a bug in axon server? Or do I have to take precautions to prevent multiple commands to the same instance of an aggregate? How could I prevent this?

Greetings,
Erik

It seems to help to use @RoutingKey, So I declare

@TargetAggregateIdentifier @RoutingKey private String id;

in my command.

Why is this RoutingKey annotation solving the problem? Would it be better to use the with the @TargetAggregateIdentifier annotation unless a routing key is supplied?

Hi Erik,

the @TargetAggregateIdentifier annotation is itself meta-annotated with @RoutingKey. It shouldn’t make a difference.
It doesn’t seem like an issue in AxonServer, as it just routes commands. However, because you say that no commands come through for the same aggregate after the timeout, I suspect that there is a lock still being held on that aggregate identifier.
Note that CREATE_IF_MISSING does force a load on AxonServer, which means it will need to go all the way back to the beginning of the event store to find events for the aggregate.

I will try to find some time to reproduce this.
Kind regards,

Hi Allard,
you are correct, the @RoutingKey annotation does not help.
I have a part of my application (an importer) I want do be repeated on a regular basis. So I have a spring component which is @Scheduled.
Sometimes the problem occurs right from the start, sometimes some cycles work, but after a few cycles, the command is sent, but does not reach the command handler.
To be pricise, no other command reaches its command handler anymore, the system is blocking any command.

Hi Erik,

I’ve been bashing a system with a ton of create if missing commands in large succession, but everything seems to work fine.
Could it be that the sendAndWait creates some sort of deadlock, where the sending component holds a lock on something that the handling component also needs to acquire?

Hi Allard,
I’m investigating the problem since the beginning of the day, and it keeps getting worse.
To provoke the problem I don’t need many commands, and it occurs without the CreationPolicy.
I restart the system, few commands work and then the axon server seems to freeze. The commands run into the axon server, it even increments its counter, but the commands are not sent to target process. After that nothing works anymore. :frowning:

To bring this to an end: I reworked the configuration, using the spring boot starter. This magically solved all the problems.