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
790
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
Designing for humans not robots
tammielis
254
26k
Prompt Engineering for Job Search
mfonobong
0
530
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
12
1.3k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.4k
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.6k
Learning to Love Humans: Emotional Interface Design
aarron
275
41k
Crafting Experiences
bethany
1
390
The Cost Of JavaScript in 2023
addyosmani
55
10k
Getting science done with accelerated Python computing platforms
jacobtomlinson
2
540
Exploring anti-patterns in Rails
aemeredith
4
540
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
69
67k
Git: the NoSQL Database
bkeepers
PRO
433
67k
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