Need advice on using XState to implement a network protocol #1627
Unanswered
HerbCaudill
asked this question in
Q&A
Replies: 1 comment 5 replies
-
Here's a defer/recall strategy that you can use: #1305 (comment) |
Beta Was this translation helpful? Give feedback.
5 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I'm using XState to implement a peer-to-peer authentication protocol. Events are all network messages received from the peer.
Most of the time, things work as expected - something like this:
I have an intermittent bug that results from the timing of message delivery. For example, suppose Alice's
HELLO
message to Bob is delayed in transit, and when herCLAIM
message arrives, Bob is still in theInitializing
state, which doesn't respond to theCLAIM
message. By the time Bob enters theawaiting identity claim
state, it's too late - theCLAIM
message has been discarded, so the process hangs.This will also fail if messages are delivered in a different order than they were sent - for example, if
CLAIM
is delivered beforeHELLO
.I'm thinking that I'll probably need to solve this outside of XState, with a message delivery layer that queues up messages as they come in, orders them correctly, and only delivers them when the state machine is ready. I'll probably need a timeout/retry mechanism as well.
I would imagine that others have come across this kind of issue when using XState to implement network protocols - are there any good examples out there? And are there any mechanisms within XState for dealing with these kinds of issues?
Beta Was this translation helpful? Give feedback.
All reactions