What are the possible scenarios in which a go routine
, which has to run forever, can get terminated?
If it is in a non-terminating for loop it will only exit on a panic, or if the OS kills the process (program) or the machine goes down.
From the documentation,
Execution errors such as attempting to index an array out of bounds trigger a run-time panic equivalent to a call of the built-in function panic with a value of the implementation-defined interface type runtime.Error.
Apart from that, it can panic
when memory is not sufficient.
If a go routine
encounters a panic
, defer-panic-recover
can be used to handle it. This link to the official document provides more information on usage of it.