execstream

package
v0.31.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 3, 2026 License: GPL-3.0 Imports: 10 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package execstream is the wire protocol of `preview exec`: a byte stream of typed frames multiplexing an interactive exec session — stdin, stdout, stderr, terminal resizes, the final exit code, and transport-level errors — over a single bidirectional connection. The same frames ride every hop (CLI ↔ control API ↔ worker API ↔ supervisor), so a control node forwarding a session to a worker copies bytes blindly, without re-framing.

Each frame is a 1-byte type, a 4-byte big-endian payload length, then the payload. The carrier is a WebSocket (see Accept/Dial) treated as a plain byte stream: WebSocket is the one upgrade ALBs and proxies reliably pass through, and the CSRF story (browser-enforced Origin on ws handshakes) comes for free.

Index

Constants

View Source
const (
	FrameStdin byte = iota + 1
	FrameStdout
	FrameStderr
	// FrameExit carries the command's exit code as one byte (0–255). It is
	// the last frame of a successful session.
	FrameExit
	// FrameResize carries cols then rows, each big-endian uint16.
	FrameResize
	// FrameStdinEOF signals the client closed stdin (payload empty); the
	// executed command sees EOF but the session keeps streaming output.
	FrameStdinEOF
	// FrameError carries human-readable text for a session that failed for
	// transport or orchestration reasons (as opposed to a command exiting
	// non-zero, which is FrameExit).
	FrameError
	// FramePing is a client keep-alive (payload empty) — traffic that stops a
	// load balancer's idle timeout from severing a quiet session. Receivers
	// ignore it, as they do any unknown frame type.
	FramePing
)

Frame types. Stdin, StdinEOF, and Resize flow client→server; Stdout, Stderr, Exit, and Error flow server→client.

View Source
const MaxPayload = 1 << 20

MaxPayload bounds one frame's payload, and so the allocation a peer can force per frame. Writers chunk larger payloads across frames.

Variables

This section is empty.

Functions

func Accept

func Accept(w http.ResponseWriter, r *http.Request) (net.Conn, error)

Accept upgrades an HTTP request to the exec byte stream. It clears the server's per-request deadlines first — an interactive session outlives any ReadTimeout — and returns a net.Conn carrying the frame protocol. The WebSocket handshake enforces same-origin for browser callers; non-browser clients (the CLI, a control node) send no Origin and pass.

func DecodeResize

func DecodeResize(p []byte) (cols, rows uint16, err error)

DecodeResize decodes a FrameResize payload.

func Dial

func Dial(ctx context.Context, url string, header http.Header) (net.Conn, error)

Dial opens the exec byte stream against url (http/https, or ws/wss), sending header on the handshake. A failed handshake surfaces the HTTP response body when there is one — that's where the API's JSON error lands.

func ResizePayload

func ResizePayload(cols, rows uint16) []byte

ResizePayload encodes a terminal size for FrameResize.

Types

type ExitError

type ExitError struct{ Code int }

ExitError is a session that ended with the command exiting non-zero — distinct from transport failures so callers can propagate the code.

func (ExitError) Error

func (e ExitError) Error() string

type Frame

type Frame struct {
	Type    byte
	Payload []byte
}

Frame is one decoded frame.

func ReadFrame

func ReadFrame(r io.Reader) (Frame, error)

ReadFrame reads the next frame, rejecting payloads beyond MaxPayload.

type RemoteError

type RemoteError struct{ Msg string }

RemoteError is a FrameError received from the peer.

func (RemoteError) Error

func (e RemoteError) Error() string

type StreamWriter

type StreamWriter struct {
	FW   *Writer
	Type byte
}

StreamWriter adapts one frame type to io.Writer — the output pumps copy into these.

func (StreamWriter) Write

func (s StreamWriter) Write(p []byte) (int, error)

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer frames payloads onto an underlying stream. Safe for concurrent use — an exec session writes output and the exit frame from different goroutines.

func NewWriter

func NewWriter(w io.Writer) *Writer

NewWriter wraps w.

func (*Writer) WriteFrame

func (fw *Writer) WriteFrame(t byte, payload []byte) error

WriteFrame writes one frame, chunking payloads larger than MaxPayload.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL