context 使用规范:取消、超时与请求级数据
context.Context 的作用是把取消信号、截止时间(deadline)和请求级数据沿调用链向下传递。一次请求自 HTTP handler 进入,经过 service、数据库、下游服务,属于这条链的操作都应派生自同一个 ctx。若取消信号未从入口传到底层,客户端断开后,服务端仍会继续执行已无意义的查询,持续占用 goroutine 与连接等资源。
9 min read
Loading…
Quote of the day · October 26 · 关于意义 · Rick and Morty
Nobody exists on purpose. Nobody belongs anywhere. Everybody's gonna die. Come watch TV?
Notes on Agent runtimes — design decisions laid open: why it is this way, what it costs, and when it stops being true.