huan/mailbox

Race condition: two NEW_MESSAGEs concurrency lost one

huan opened this issue · 1 comments

huan commented
Actor: (bot5-assistant/Idle) + [bot5-assistant/MESSAGE] = (bot5-assistant/Parsing)
-------------------------
WechatyActor<Mailbox> contexts.queueAcceptingMessageWithCapacity(Infinity) queue [cqrs-wechaty/SEND_MESSAGE_COMMAND]@x:5 for child(idle)
WechatyActor<Mailbox> contexts.queueAcceptingMessageWithCapacity(Infinity) queue [wechaty-actor/BATCH]@x:5 for child(idle)
WechatyActor<Mailbox> states.child.idle.on.NEW_MESSAGE (cqrs-wechaty/SEND_MESSAGE_COMMAND)
WechatyActor<Mailbox> states.child.idle.on.NEW_MESSAGE (wechaty-actor/BATCH)
WechatyActor<Mailbox> states.queue.checking.entry <- [DISPATCH(mailbox/NEW_MESSAGE)]
WechatyActor<Mailbox> states.queue.checking.always -> dequeuing (queue size 2 > 0)
WechatyActor<Mailbox> states.queue.dequeuing.entry [cqrs-wechaty/SEND_MESSAGE_COMMAND]@x:5
WechatyActor<Mailbox> states.queue.listening.entry
WechatyActor<Mailbox> states.queue.checking.entry <- [DISPATCH(mailbox/NEW_MESSAGE)]
WechatyActor<Mailbox> states.queue.checking.always -> dequeuing (queue size 1 > 0)
WechatyActor<Mailbox> states.queue.dequeuing.entry [wechaty-actor/BATCH]@x:5
WechatyActor<Mailbox> states.queue.listening.entry
WechatyActor<Mailbox> states.child.idle.on.DEQUEUE [cqrs-wechaty/SEND_MESSAGE_COMMAND]@x:5
WechatyActor<Mailbox> states.child.busy.entry DEQUEUE [cqrs-wechaty/SEND_MESSAGE_COMMAND]
WechatyActor State.Preparing.entry
WechatyActor State.Preparing.entry found Command/Query [cqrs-wechaty/SEND_MESSAGE_COMMAND]
______________________________
Wechaty: (wechaty-actor/idle) + [cqrs-wechaty/SEND_MESSAGE_COMMAND] = (wechaty-actor/preparing)
-------------------------
WechatyActor State.Executing.entry EXECUTE [cqrs-wechaty/SEND_MESSAGE_COMMAND]
______________________________
Wechaty: (wechaty-actor/preparing) + [wechaty-actor/EXECUTE] = (wechaty-actor/executing)
-------------------------
______________________________
Wechaty: (wechaty-actor/executing) + [done.invoke.WechatyActor.wechaty-ac

We can see there's two NEW_MESSAGEs have been accepted by the Mailbox, which should be only accepted one:

WechatyActor<Mailbox> states.child.idle.on.NEW_MESSAGE (cqrs-wechaty/SEND_MESSAGE_COMMAND)
WechatyActor<Mailbox> states.child.idle.on.NEW_MESSAGE (wechaty-actor/BATCH)
huan commented

Fixed by the Atomic wrapper PR #6

It seems that the event between parallel states can not guarantee atomic transitions.