Menu

1 / 2

context.WithoutCancel: When You Need Work That Outlives Its Caller

DEV Community·Gabriel Anhaia·6 months ago
#YAXGzgdR
#go#concurrency#stdlib#backend#context
Reading 0:00
15s threshold

Book: The Complete Guide to Go Programming

Also by me: Thinking in Go (2-book series) — Complete Guide to Go Programming + Hexagonal Architecture in Go

My project: Hermes IDE | GitHub — an IDE for developers who ship with Claude Code and other AI coding tools

Me: xgabriel.com | GitHub

A team I worked with had a billing service. Every successful

checkout fired one final write: an audit-log row, async, after the

HTTP response had already gone out. The handler did the right

shape: spawn a goroutine, pass the request context, write the

audit row.

Then they turned on aggressive client-side cancellation. The

mobile client tore down the request the instant it had its 200,

because mobile networks. The HTTP server cancelled the request

context the moment the client hung up. The goroutine inherited

that cancellation and the audit-log write returned

context.Canceled before it ever hit the database.

The audit log started missing rows.…

Continue reading — create a free account

Join HashtagPLUS to read full articles, follow hashtags, vote, and join the conversation.