Skip to content

Docs: Stream state machine

Jeff Wendling edited this page Apr 29, 2021 · 6 revisions

State transitions

Message receive

Cancel Close Error[E] CloseSend
open canceled term[RClosed] term[E] recv-closed
send-closed canceled term[RClosed] term[E] term[Mutual]
recv-closed canceled term[RClosed] term[E] recv-closed
term[X] term[X] term[X] term[X] term[X]
canceled canceled canceled canceled canceled

Message send

Close Error[E] CloseSend
open term[SClosed] term[Errored] send-closed
send-closed term[SClosed] term[Errored] send-closed
recv-closed term[SClosed] term[Errored] term[Mutual]
term[X] term[X] term[X] term[X]
canceled canceled canceled canceled

Finished

After a stream is in any term[X] or canceled state, after all MsgSend or MsgRecv operations have completed, the stream becomes finished in addition to the current state it is in. In this state, it is sure that the stream will no longer attempt to perform any network operations.

Operation Results

Any operation can have one of four results:

  • Ok: The operation does not fail due to the stream state, but it may fail due to network failures or state transitions while it is ongoing.
  • !Ok: The operation is guaranteed to fail with some unspecified (not EOF or Canceled) error. Each !Ok entry may be a unique error.
  • EOF: The operation is guaranteed to fail with an EOF sentinel error.
  • Canceled: The operation is guaranteed to fail with some canceled sentinel error.
MsgSend MsgRecv
open Ok Ok
send-closed !Ok Ok
recv-closed Ok EOF
term[Errored] EOF !Ok
term[SClosed] !Ok !Ok
term[RClosed] !Ok EOF
term[Mutual] EOF EOF
term[X] EOF !Ok
canceled EOF Canceled