Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Go 1.26 リリースパーティ
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
sivchari
February 26, 2026
330
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Go 1.26 リリースパーティ
sivchari
February 26, 2026
More Decks by sivchari
See All by sivchari
go test を速くする
sivchari
4
1.6k
govalid ~ Type-safe validation tool ~
sivchari
0
240
Go1.25 リリースパーティ ~ nil pointer bug ~
sivchari
0
230
Google Developer Group - DevFest Tokyo 2025
sivchari
0
240
Who tests the Tests ?
sivchari
0
280
静的解析 x Kubernetes API Conventions = Kube API Linter ~ ベストプラクティスに準拠したカスタムリソースの作り方と運用 ~
sivchari
0
360
What's GOCACHEPROG ?
sivchari
1
680
gh_extensionsによる快適なOSS生活.pdf
sivchari
0
270
Visualization Go scheduler by gosched-simulator
sivchari
1
770
Featured
See All Featured
Into the Great Unknown - MozCon
thekraken
41
2.8k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
4 Signs Your Business is Dying
shpigford
187
23k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
123
22k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
141
35k
Accessibility Awareness
sabderemane
1
260
VelocityConf: Rendering Performance Case Studies
addyosmani
331
25k
A Soul's Torment
seathinner
8
3.8k
Dominate Local Search Results - an insider guide to GBP, reviews, and Local SEO
greggifford
PRO
0
380
Fashionably flexible responsive web design (full day workshop)
malarkey
409
67k
Rails Girls Zürich Keynote
gr2m
96
14k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
Transcript
Go 1.26 リリースパーティ goroutine leak profileについて The Go gopher was
designed by Renee French
もくじ • goroutine leak profileとは • goroutine leakの検出方法 • goroutine
leakを検出できないケース • まとめ
自己紹介 渋谷拓真 Go Conference メインオーガナイザー OSS ◦ Kubernetes メンテナー ◦
Argo CD メンテナー Kubernetes 2025 Contributor Award 3Dプリンターにハマってます
goroutine leak profileとは
goroutine leak profileとは Go 1.26で追加された新しい pprof profile • CL#688335 •
ブロックされており復帰不可能な goroutineを検出する • GCの到達可能性を利用する • 1.26ではGOEXPERIMENTで、1.27からはデフォルトになる予定
goroutine leak profileとは GOEXPERIMENT=goroutineleakprofile go build -o myapp • net/http/pprof
• runtime/pprof goroutine 123 [chan send] (leaked): main.leaky.func1() /path/to/main.go:25 +0x1c created by main.leaky in goroutine 1 /path/to/main.go:24 +0x2c
goroutine leakの検出方法
goroutine leak profileの検出方法 内部でgoroutineleak profileがリクエストされた時にトリガーされる net/httpでもruntime/pprofでも(&Profile).WriteToが呼ばれる var goroutineLeakProfile = &Profile{
name: "goroutineleak", count: runtime_goroutineleakcount, write: writeGoroutineLeak, }
writeGoroutineLeak リーク検出用の GCをトリガーする関数を呼ぶ runtime_goroutineLeakGC() //golinkename runtime_goroutineLeakGC runtime.goroutineLeakGC func runtime_goroutineLeakGC()
runtime_goroutineLeakGC goroutineLeakを確認するチェックをつける func goroutineLeakGC() { work.goroutineLeak.pending.Store(true) for work.goroutineLeak.pending.Load() { GC()
} }
なぜGCに組み込むのか リーク検出は特定の goroutineを操作できない状態 • GCは到達不可能なオブジェクトを削除する • GCのマークを活用することで到達可能性を検出できる
しかしそのまま使いまわせない Goは内部でallgsという変数から全ての goroutineに到達できてしまう • waiting(*sudog)を使用してブロッキングかどうかは確認できてしまう • ブロッキングでも参照できてしまいリークかどうかわからなくなる allgs → blocking
g → sudog → c → blocking channel
maybeTraceablePtrの導入 リーク検出時の GCでは追跡を行わないようにポインタを nilにする • nilのため以降の GCで追跡対象に含めないようにする • リーク検出後にマークして追跡対象に戻すため回収されてしまうリスクは 回避している
gcPrepareMarkToots goroutine leakを検出する場合はソートして先頭実行可能・末尾ブロック中 に並べ替える if work.goroutineLeak.enabled { work.stackRoots, work.nMaybeRunnableStackRoots =
allGsSnapshotSortedForGC() } else { work.stackRoots = allGsSnapshot() work.nMaybeRunnableStackRoots = len(work.stackRoots) }
findGoroutineLeaks マーク完了後に Eventually Runnableでなければリークとみなす if findMaybeRunnableGoroutines() { return false }
for i := work.nMaybeRunnableStackRoots; i < work.nStackRoots; i++ { gp := work.stackRoots[i] casgstatus(gp, _Gwaiting, _Gleaked) shadePrimitivesOnLeak(gp) }
Eventually Runnableとは 実行可能な sudogのchannelがマークされている • 実行可能な goroutineがアクセスできる • リークを疑われていたがリークではないと考える
Eventually Runnableとは 実行可能な sudogのchannelがマークされている • 実行可能な goroutineがアクセスできる • リークを疑われていたがリークではないと考える
findGoroutineLeaks sharedPrimitivesOnLeakでリーク対象もマーキングして回収防止 if findMaybeRunnableGoroutines() { return false } for i
:= work.nMaybeRunnableStackRoots; i < work.nStackRoots; i++ { gp := work.stackRoots[i] casgstatus(gp, _Gwaiting, _Gleaked) shadePrimitivesOnLeak(gp) }
goroutine leakを検出できないケース
一部ケースは検出できない 銀の弾丸ではない • グローバル変数に定義されている • グローバルはマークされてしまう ◦ Eventually Runnableと判定 var
ch = make(chan int) func leaky() { go func() { ch <- 42 }() }
一部ケースは検出できない 銀の弾丸ではない • ローカル変数で使用されている • fがforで実行されて runnable ◦ Eventually Runnableと判定
• forのなかでchのselectがあったら ◦ waitingとなり検出される func leaky() { ch := make(chan int) go f(ch) go func() { ch <- 42 }() } func f(ch chan int) { for {} }
まとめ
まとめ • Go1.26からgoroutine leakを検出できるようになった • GCの持つ到達可能性の追跡を活用している • uberのgoleakと併用して lekaを防止しよう!
ありがとうございました!
おしらせ