concurrency

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Oct 26, 2026 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Overview

Package concurrency is the only place in the project where a `go` statement may appear.

Background: a panic in a bare goroutine kills the whole process, no matter how carefully the request path is guarded. That defeats the "should essentially never crash" goal (ADR-0016). The architecture test in test/architecture enforces that no `go` statement occurs outside this package.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Go

func Go(ctx context.Context, component string, fn func(context.Context))

Go runs fn concurrently. A panic does not terminate the process; it is logged and reported instead. component names the location for the metric and the log.

func Recover

func Recover(ctx context.Context, component string)

Recover is the reusable guard for request handlers and job execution. Usage: defer concurrency.Recover(ctx, "rest.handler")

It has to be the deferred function itself - `defer Recover(...)`, never a call from inside another deferred closure - because recover() only works one frame deep. A caller that needs to do something afterwards (write a 500, finish a span) recovers itself and calls Report.

func Report

func Report(ctx context.Context, component string, recovered any)

Report counts and logs an already recovered panic. It is the half of Recover that a caller needs when the panic is not the end of the story: an HTTP middleware still owes the client a response, and it cannot write one from a frame that Recover has swallowed.

Both paths go through here, so hubtask_panics_recovered_total has exactly one source.

func SetPanicObserver

func SetPanicObserver(o PanicObserver)

SetPanicObserver is set once at startup by the observability layer.

Types

type PanicObserver

type PanicObserver func(component string, recovered any)

PanicObserver is called for every recovered panic. The metric hubtask_panics_recovered_total hangs off this - its target value is permanently 0.

Jump to

Keyboard shortcuts

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