4 ms·
There's a problem lurking behind this "simple" model: the goroutine you park on that blocking IO operation can't be collected reliably itself. I care about col
by heavenlyhash 10y ago
There's a problem lurking behind this "simple" model: the goroutine you park on that blocking IO operation can't be collected reliably itself.
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-without-knowing-how-it-will-stop https://dave.cheney.net/2016/12/22/never-start-a-goroutine-w...
- https://rakyll.org/leakingctx/ https://rakyll.org/leakingctx/
- tptacek 10y agoIt's particularly a problem with timeouts and file descriptors.
- lobster_johnson 10y agoThat's also a great point. I also wish for supervisor trees and killable processes.
- heavenlyhash 10y agoThis is an attempt to implement supervisor trees in go as a library: https://github.com/polydawn/go-sup 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!
- lobster_johnson 10y agoThat 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.