Skip to content
所有文章 ‹ Part 11 of 11 · 從 19 個 goroutine 到 exit 137
工程 · 2 min read

錯誤的修法:GOMEMLIMIT 調錯 process、git 考古才找到原因

fix-locus ≠ failure-locus 等於修了白修。GOMEMLIMIT 管不到瀏覽器 OOM,git 考古才知道為什麼之前沒事。

fix-locus(修的地方)≠ failure-locus(壞的地方)→ 修了等於沒修。

調錯 process

Go app container heap: 256Mi GOMEMLIMIT set here Browser sidecar mem limit: 2Gi 19 tabs → OOM → exit 137 ✗ can't see Browser's memory ✗ GOMEMLIMIT doesn't reach fix-locus ≠ failure-locus → fix is inert
  • 確認 fix-locus == failure-locus:同一個 process、同一個 kernel kill 掉的資源。看起來「相關」的控制可能完全不相關。
  • GOMEMLIMIT 管的是 Go heap only,不管 cgo、mmap、stack、其他 process(執行環境)。
  • Red flag:一個標題寫「fix OOM」的 commit,調的卻是另一個 process。

git 考古:為什麼以前不會?

2025-01 ExecAllocator (per-request browser) blast radius: 1 request commit A → RemoteAllocator (shared browser) blast radius: ALL in-flight commit B → retry re-added multiplier on shared browser commit C → "fix OOM" → GOMEMLIMIT on Go heap ✗ wrong process 2026-07 OOM incident (exit 137)
  • Bug 是「新的」但程式碼從來沒有保護。問題是「什麼改變了條件」。git log 回答。
  • 看 architecture swaps(獨立→共用)、retry changes(倍增器)、resource-limit edits(錯誤目標)。
  • chore: / refactor: commit 可能靜默翻轉 failure mode,diff 看機制,不看 ticket title。

教訓

  1. 修之前,確認你要修的東西跟掛的東西是同一個 process。
  2. 「以前不會」→ git log --since=<date> --reverse -- <hot-file> 找出什麼改了條件。
  3. 找之前的「修復嘗試」:它們透露團隊的 mental model,有時候也透露 model 是錯的。

最危險的修法是「看起來相關、其實完全不相關」,因為它在 code review 裡不會引來質疑,在 OOM 裡也不會有任何效果。

參考來源:

延伸閱讀: 參見執行環境、GOMAXPROCS 限制平行不限並發、共享資源的影響範圍,或回到系列總覽。

↑↓ 移動 ↵ 開啟 esc 關閉