Go问答
已收录文章:17篇
-
Golang · Go问答 | 5天前 | channel · goroutine · pprof · Go问答 · 线上排查 · pprof Go问答 Go channel阻塞 goroutine堆积 channel发送Go 服务出现 goroutine 数持续上涨、接口超时或后台任务堆积时,channel 发送阻塞是常见原因之一。排查时先看 goroutine profile 里的 chan send,再确认接收方是否退出、消费是否变慢、缓冲是否打满,并用超时退出或限流恢复服务。205 收藏
-
Golang · Go问答 | 3天前 | goroutine · Context · 超时控制 · Go问答 · 协程泄漏 · Go Goroutine 超时控制 context.WithTimeout 取消信号 协程泄漏 ctx.Donecontext.WithTimeout 只会在到期后关闭 Done 通道并返回取消原因,不会直接停掉 goroutine。Go 代码要把 ctx 传进阻塞调用,并在 select、循环和清理逻辑里主动响应取消信号。147 收藏
-
Go 的 internal 包不是用来显得项目高级,而是给仓库内部代码加编译期边界。判断重点看复用范围、依赖方向、测试替身和未来演进成本。127 收藏
-
Golang · Go问答 | 3天前 | goroutine · HTTP · Context · 超时控制 · Go问答 · WithTimeout Go问答 context取消 QueryContext HTTP请求取消 goroutine退出Go HTTP 请求断开后,r.Context() 会收到取消信号,但服务端慢任务不会凭空停止。只有把 context 继续传给数据库、下游 HTTP 调用、消息消费和 goroutine,取消与超时才会真正变成资源释放动作。120 收藏
-
Golang · Go问答 | 5天前 | 并发安全 · RWMutex · sync.Map · Go问答 · map并发 · RWMutex sync.Map Go问答 Go map并发读写 concurrent map writesGo map 不是并发安全容器,多个 goroutine 同时写或读写交错时可能触发 fatal error。本文从线上 panic 现场出发,说明如何复现、定位原因,并在 RWMutex、sync.Map 和单 owner 模型之间做选择。102 收藏