Re:Goroutines, Nonblocking I/O, and Memory Usage
by lobster_johnson on Friday January 06, 2017 @08:31PM
(#13341865)
That's also a great point. I also wish for supervisor trees and killable processes.
Re:Goroutines, Nonblocking I/O, and Memory Usage
by heavenlyhash on Saturday January 07, 2017 @07:31AM
(#13343825)
This is an attempt to implement supervisor trees in go as a library: https://github.com/polydawn/go-sup (Hej; author.)
It takes the Wait-for-children behavior path by default, and that seems much safer to me. The downside is, as we're describing: if you do get stuck in IO somewhere, you're a pretty unhappy camper. This library makes the choice of (by default; it's a handler func you can override) logging warnings to stderr if a task doesn't exit within 2 seconds of being told to quit... but this still feels like something of a hack; more of a debug measure than a concrete way to improve system stability. Better ideas would be highly welcome!
Re:Goroutines, Nonblocking I/O, and Memory Usage
by lobster_johnson on Saturday January 07, 2017 @01:54PM
(#13345839)
That looks very promising, actually, thanks. I'm defininitely going to try it out the next time I have a problem involving a graph of workers.
I care about collecting goroutines, and would advocate that everyone should care about this. There's been a litany [1] of blogs about this recently, if anyone doesn't consider this self-evident. It's just systematically sane. Letting goroutines spin off into the distance with no supervision is extremely likely to represent either a resource leak, a missing error handle path, or an outright logic bug.
In a dream world, we might have Erlang-style supervisor trees so this can all be done with less boilerplate. It's almost even possible to do this as a library in go! ... except for this blocking IO problem, which throws a wrench in things: any supervisor of a goroutine that may be IO-blocked may itself be indefinitely stuck, and so on up-tree, making the concept unworkable.
---
[1] Some recent articles hammering the point of "collect your goroutines":
- https://dave.cheney.net/2016/12/22/never-start-a-goroutine-w...
- https://rakyll.org/leakingctx/