Is it possible to kill a goroutine just like you could use Thread.Abort
to kill a thread in Java?
I opened this issue: https://github.com/golang/go/issues/50678
The conclusion is that, if we patch Golang’s src/runtime
, it is possible. But in doing so, we may break some of Golang’s invariants, and make introduce bugs that are very difficult to troubleshoot. So, be very careful!
I will share in this blog, how I hacked Golang to support killing goroutine, how to publish the hacked Golang as a docker image (so that it will be easy to build programs with this hacked Golang), and how to make the code compatible with non-hacked Golang (so the kill method will be a no-op and just return false).
(to be continued)