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

Race condition: two NEW_MESSAGEs concurrency lost one #5

Closed
huan opened this issue Apr 18, 2022 · 1 comment
Closed

Race condition: two NEW_MESSAGEs concurrency lost one #5

huan opened this issue Apr 18, 2022 · 1 comment
Labels
bug Something isn't working

Comments

@huan
Copy link
Owner

huan commented Apr 18, 2022

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 huan added the bug Something isn't working label Apr 18, 2022
huan added a commit that referenced this issue Apr 18, 2022
@huan huan mentioned this issue Apr 19, 2022
huan added a commit to wechaty/bot5-assistant that referenced this issue Apr 19, 2022
@huan
Copy link
Owner Author

huan commented Apr 19, 2022

Fixed by the Atomic wrapper PR #6

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

@huan huan closed this as completed Apr 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant