title: Are deferred functions called when SIGINT is received in Go?
body: <p>For the snippet below, the deferred call is not made when ^C is received. Is it possible that the cleanup introduces a race condition? If yes, what could be a better pattern of cleanup on receiving an interrupt?</p>
  
  <pre><code>  func fn() {
      // some code
      defer cleanup()
      go func() {
         c := make(chan os.Signal, 1)
         signal.Notify(c, os.Interrupt)
  
         // Block until a signal is received.
         _ = &lt;-c
         cleanup()
       }
       for {
          // Infinite loop. Returns iff an error is encountered in the 
          // body
       }
  }
  </code></pre>