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
goroutine で panic すると親プロセスをまきこんで落ちる
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
uji
February 21, 2021
2.2k
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
goroutine で panic すると親プロセスをまきこんで落ちる
uji
February 21, 2021
More Decks by uji
See All by uji
【Go ハンズオン】Windows / Linux コマンドを Go で再現
uji
1
130
testdata ディレクトリを活用しよう!
uji
1
500
MCP 公式の Go SDK で QA データ登録アシスタントを作ってみた
uji
0
190
Green Tea GCの動作を紙芝居にしてみる
uji
1
230
Go Proverbs の紹介
uji
2
240
Go標準の暗号ライブラリメンテナンス戦略
uji
3
780
NOT A HOTEL TECH TALK ーSOFTWARE 3.0への道筋ー NEXT Web3 (2024-08-07)
uji
0
280
マネーフォワード ME ブロックチェーン連携機能におけるGoの活用方法
uji
1
340
Goはブロックチェーン領域でなぜ使われ、どのように活躍しているのか
uji
1
840
Featured
See All Featured
Primal Persuasion: How to Engage the Brain for Learning That Lasts
tmiket
0
500
Skip the Path - Find Your Career Trail
mkilby
1
260
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
480
Visual Storytelling: How to be a Superhuman Communicator
reverentgeek
2
710
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
52
6.1k
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
300
Building Flexible Design Systems
yeseniaperezcruz
330
41k
HDC tutorial
michielstock
2
960
A Soul's Torment
seathinner
8
3.8k
Applied NLP in the Age of Generative AI
inesmontani
PRO
4
2.5k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
47
8.4k
Statistics for Hackers
jakevdp
799
230k
Transcript
goroutine で panic すると 親プロセスをまきこんで落ちる uji @uji_rb
panic とは • 回復不能だと判断された実行時のエラーを発生させる機構 • panicが生じるとプロセスが止まる • 組み込み関数のpanicを呼び出すと発生する
panic のハンドリング • panic は defer + recover でハンドリングできる https://play.golang.org/p/sXEcmsxtV_Z
しかし... goroutine で panic が起こった場合 親プロセスからはハンドリングできない
goroutine の panic • goroutine 内で panic のハンドリングがされていないと 親プロセスごと落ちる https://play.golang.org/p/HUY-sN8PK-X
ぶち当たった問題 • api サーバーで goroutine を使った処理が panic が起こすとプロ セスがまるごと落ちてしまう apiサーバー
メインプロセス リクエスト プロセス リクエスト プロセス リクエスト プロセス リクエスト 子プロセス リクエスト 子プロセス
解決策 • goroutine 内ではなるべく panic が 起こらないようにする (error によるハンドリングを徹底)
• goroutine 内で panic の恐れがある場合は recover 処理を忘れない →汎用的につかえる並列処理実行関数をつくった
参考 • プログラミング言語Go完全入門 https://docs.google.com/presentation/d/1HW3wG8J_Q2536Iu__7HGr_mhurHajC7IOGjCnn3kZmg/edit?usp=sharing