grpcproc
Documentation

Errors and exit reasons

The errors the API returns, what each says about whether a call was handled, and the reasons a process exits with.

An error is what a call to the API returns to the code that made it. An exit reason is a string that says why a process ended, and it reaches the processes that watch it as a message. A process that was asked to exit sees an *ExitError, whose reason is what its watchers get.

Errors

ErrorWhen
ErrNoProcNo such process: a Call to a PID or a name nothing holds, or a callee that exited before answering. A Send to no process is a dead letter, not an error.
ErrNoConnectionThe peer cannot be reached. It comes as a *LinkError wrapping the transport error, with the peer's name and Unsent; errors.Is matches it.
ErrLinkBusyThe link to the peer holds as much as Config.MaxQueued or MaxQueuedBytes allow: the peer cannot keep up. It comes as a *LinkError with Unsent set, and matches ErrNoConnection too.
ErrTooLargeA message or a call to another node encodes larger than Config.MaxMessageSize allows, gRPC's 4 MiB receive limit unless raised: it was never sent. From a Call it can also be the callee's reply that was too large, as a *RemoteError: the call was handled, and Reply returned the same error.
ErrMailboxFullA Call to a process whose mailbox holds as much as WithMailboxLimit allows. The process never saw the call, so making it again cannot run it twice. A Send to such a process is a dead letter instead, on this node or another.
ErrTypeThe process does not accept this message type, or a Call's reply is not the R the caller asked for.
*RemoteErrorThe error a Call handler returned, carried back as text. The type says where it came from; the text is the handler's. errors.Is matches it by that text, so a handler that answers with a sentinel error, actor.ErrBusy or one of your own, gives the caller an error that is the sentinel to errors.Is.
ErrNameTakenA Spawn with WithName while another process holds the name.
ErrNodeStoppedThe node has stopped, or stopped while a call waited.
ErrNotCallA Reply to a message nobody waits on.
ErrNotLocalDeclared for a PID of another node handed to a method that takes local ones. The core's own methods, Inspect and SetLogLevel, answer ErrNoProc for such a PID instead: a process of another incarnation, or another node, is not one this node has.
*ExitErrorWhat Receive returns, and what context.Cause(p.Context()) is, once a process was asked to exit or a process it is linked to exited. Its Reason is the exit reason. When the node stops instead, both are context.Canceled.
actor.ErrBusyA supervisor's reply to a call while it has waited more than 100 ms for a child to exit; from a process, call it with p.Context().
actor.ErrWorkersBusyReturned by Workers.ReplyLater when all its workers are answering, without running the call's fn. HandleCall returning it answers the caller, who gets a *RemoteError that is it to errors.Is; making the call again cannot run it twice.
actor.ErrAlreadyStartedA StartChild or StartChildFrom of a name the supervisor already runs a child under. It comes with that child's PID, so a caller that starts a child unless it runs takes the PID either way; from StartChildFrom, with the monitor it asked for, on that child.
actor.ErrNoFactoryA StartChildFrom of a factory the supervisor's Spec.Factories does not have. A refusal of the factory's own is its error, as it returned it.
actor.ErrNoReplyReturned from HandleCall: the actor answers later, with m.Reply, from any goroutine.
actor.ErrStopReturned from a handler: the actor ends normally, after replying if it was a call.
grpcprocetcd.ErrSupersededRegister found a newer incarnation of this node in etcd. The instance was replaced, and does not take the name back.

*LinkError implements Is for ErrNoConnection and Unwrap for the transport error, so both tests work, and errors.AsType gets at the fields:

_, err := stock.Call[*shoppb.Reserved](ctx, node, req)
if le, ok := errors.AsType[*grpcproc.LinkError](err); ok && le.Unsent {
	// The message never left this node: sending it again cannot deliver it twice.
}
if errors.Is(err, grpcproc.ErrNoConnection) {
	// Any link failure, whether or not the message left.
}

Retrying a failed call

Delivery is at most once. A Send that returns nil was handed to delivery, which means the mailbox for a local process and the link's queue for a remote one; a Call that returns a reply was handled. For any other outcome, the error says whether the callee saw the request, where that is known:

  • A *LinkError with Unsent set says no. The peer could not be reached, dials to it are backed off, or its link is full, and the message is still on this node. Sending it again cannot deliver it twice.
  • A *LinkError without it says the message may have been handled: the link broke while the call waited for its reply. So does a call that ended with its context, and one that was waiting when its node stopped, which fails with ErrNodeStopped.
  • ErrNoProc says no when the process did not exist, and maybe when the callee exited before answering: it may have done the work and crashed on the reply.
  • ErrType and a *RemoteError say the callee saw the request, refused it, or handled it and returned an error.

Unsent is the field, rather than Sent, so that a LinkError built without it claims nothing. A caller that retries on anything else risks doing the work twice; whether that is safe depends on the handler. The tutorial's desk does not retry: on an error it leaves things as they are, logs the order for reconciliation, and fails the call.

Exit reasons

A process exits with a reason, a string. Its watchers get it in a Down, the processes linked to it exit with it or receive it in an Exited, the node publishes it in an EventExit, and hooks see it in OnExit. The reasons that grpcproc itself produces are constants: ReasonNormal, ReasonShutdown and so on.

ReasonWhere it comes from
normalThe process function returned nil, or the actor returned actor.ErrStop.
the error’s textThe process function returned an error, or an actor’s handler did.
panic: …The process panicked; the stack is logged.
goexitThe process function called runtime.Goexit, as t.FailNow does.
what Exit asked forA process or the node called Exit with that reason. It is never trapped.
shutdownThe node is stopping, or a supervisor is stopping its child, or a supervisor ended itself because its significant children ended.
killedThe Inspector's Exit, and grpcprocctl exit, with no reason given.
name lostThe process held a global name, and the store lost its claim: its node cut off from etcd past its lease. Abnormal, so a supervisor restarts it. See Global names.
name conflictA KeepOnLoss claim, made again once the store was back, found its name held by another process. Abnormal.
max restartsA supervisor restarted its children more often than its Spec allows. Abnormal, so its own supervisor restarts it.
noprocOnly in a Down or through a link: the monitored process does not exist. No process ever exits with it.
noconnectionOnly in a Down or through a link: the node the process runs on cannot be reached. Its monitors and links fire with it; the process itself may still run.
typeA dead letter's reason: the message was not of the type the process accepts. Not an exit reason.
deniedA dead letter's reason: the Policy the peer was admitted with refused its request, which the peer sees as noproc. Not an exit reason.
mailbox fullA dead letter's reason: the process's mailbox held as much as WithMailboxLimit allows. A call refused so fails with ErrMailboxFull. Not an exit reason.

A supervisor reads the reason to decide on a restart: a Transient child comes back after any reason but normal and shutdown, and a process linked to another takes the target's reason as it is, normal included. noproc and noconnection come from the node rather than a process, and only monitors and links carry them. Monitors and links has the rules.

Messages of the wrong type

A message of the wrong type is a dead letter with reason type, and ErrType to a caller, never a panic in the process. The compiler checks a send against its address's type, and the receiving node checks the message against the mailbox's on delivery, local or remote, because an address's type is the sender's claim and does not cross the wire. What a process does with a well-typed message it does not like is its own decision: the tutorial's stock logs and drops such a message rather than exit.

Dead letters

A dead letter is a message that was sent and could not be delivered: to a process that does not exist (noproc), to one that does not accept its type (type), to one the sender's node may not reach (denied, see Security), to one whose mailbox is full (mailbox full), or queued on a link that broke before or while writing it (noconnection). A message that could not be sent at all is not one: its sender got the error. A Send to no process succeeds and becomes a dead letter, because a send has no reply to carry the failure on; a Call in the same situation fails with ErrNoProc.

Each one goes three places: Hooks.OnDeadLetter with the sender, the target, the body and the reason; the DeadLetters counter in NodeInfo; and an EventDeadLetter on node.Subscribe, with the message's type. A dead-letter count that grows is a sender using a stale address, or two services that disagree about a contract, and the event says which sender and which type.