title: Golang bad file descriptor
body: <p>I am getting a bad file descriptor when trying to append to a logging file within my go routine. </p>
  
  <p><code>write ./log.log: bad file descriptor</code></p>
  
  <p>The file exists and has 666 for permissions. At first I thought well maybe it is because each one of them is trying to open the file at the same time. I implemented a mutex to try and avoid that but got the same issue so I removed it. </p>
  
  <pre><code>logCh := make(chan string, 150)
  go func() {
      for {
          msg, ok := &lt;-logCh
          if ok {
              if f, err := os.OpenFile("./log.log", os.O_APPEND, os.ModeAppend); err != nil {
                  panic(err)
              } else {
                  logTime := time.Now().Format(time.RFC3339)
                  if _, err := f.WriteString(logTime + " - " + msg); err != nil {
                      fmt.Print(err)
                  }
                  f.Close()
              }
          } else {
              fmt.Print("Channel closed! \n")
              break
          }
      }
  }()
  </code></pre>