My golang application creates UNIX sockets in specific paths: 
/mypath/name1.sock, /mypath/name2.sock etc. It then launches a go routine 
that listens to one or more of those sockets. I need to ensure that they 
get cleaned up (removed) at the end. I tried the obvious thing -- use defer 
in main() -- and eschewed the use of os.Exit() and log.Fatal(), since they 
don't ensure that defer statements are called.

However, signals like ^C also apparently cause forced termination and don't 
run the defer statements. So, I have experimented with a signal handler 
registered from main(). However, it seems that the ^C is going to the go 
routine that is actually listening on the socket: I don't see the signal 
handler running.

What is a good way to ensure that the resources are always cleaned up even 
in the presence of go routines and signals?

I have looked at related posts like 
<https://stackoverflow.com/questions/11268943/is-it-possible-to-capture-a-ctrlc-signal-and-run-a-cleanup-function-in-a-defe>
 these <https://groups.google.com/forum/#!topic/golang-nuts/q22Fx9DkFAo>.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to