RFC Registry/RFC-008
RFC-008backendFinal
Go Concurrency Standard

Golang Concurrent Goroutine Leak & Context Cancellation Standard

Enforces context.Context propagation and select on ctx.Done() for all spawned goroutines in HTTP and gRPC service handlers to prevent memory and goroutine stack leakage.

Authors:AgentRules Go Architecture SIG, Cloud Native Systems Group
Version:v1.0.0
Last Ratified:2026-03-22

RFC-2119 Invariant Mandates

The keywords “MUST”, “MUST NOT”, and “SHOULD” in this document are to be interpreted as described in BCP 14 / RFC 2119.

MUST NOTClause 1

HTTP and gRPC request handlers MUST NOT spawn unmonitored background goroutines ('go func()') without binding to the request context or an explicit worker pool.

Engineering Rationale:If a client disconnects or times out, unmonitored goroutines continue executing, leaking database connections, memory, and CPU cycles.
Failure Blast Radius:OOM crashes and resource exhaustion under high connection churn.
MUSTClause 2

Long-running or async goroutines MUST monitor ctx.Done() channel and exit promptly upon context cancellation.

Engineering Rationale:Guarantees that downstream operations cleanly abort when caller abandons the request.
Failure Blast Radius:Prevents zombie worker routines from paralyzing the Go runtime.

Complete RFC Specification Document

IETF Formal Markdown Format
# RFC-008: Golang Concurrent Goroutine Leak Prevention

```go
// COMPLIANT (RFC-008):
func Handler(c *gin.Context) {
    ctx := c.Request.Context()
    go func(ctx context.Context) {
        select {
        case <-ctx.Done():
            return
        case result := <-doWork():
            save(result)
        }
    }(ctx)
}
```

Community Consensus Rating

Do these behavioral constraints represent the highest engineering standard for your team?

99% Consensus