Error Handling
DocsImplementation GuideError Handling

Error Handling

Error codes, graceful shutdown, and GoAway

Errors in KSP are classified by scope: Connection-Level (which compromises the entire session) and Stream-Level (which only terminates a specific stream).

Error Frame Structure

Error messages are serialized as binary packets using Type = 0xFF:

+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Error Code (4 bytes) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Additional Data Length (2 bytes) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Additional Data (UTF-8, Variable) | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

Common Error Codes

CodeNameTypeDescription
0x01PROTOCOL_ERRORConnectionGeneric protocol violation, invalid header flag.
0x03FLOW_CONTROL_ERRORConnection/StreamEndpoint sent data violating window boundaries.
0x05FRAME_SIZE_ERRORConnectionPacket length field exceeded server limitations.
0x08VERSION_MISMATCHConnectionNo mutually supported protocol versions found.

Graceful Shutdown via GoAway

To safely close a connection, an initiator sends a GoAway frame containing the ID of the last stream it processed. Both sides stop creating new streams but continue processing packets for open streams until their queue is clear.