title: golang windows service fails without any error
body: <p>I have written a simple windows service using golang.</p>
  <pre><code>package main
  
  import &quot;golang.org/x/sys/windows/svc&quot;
  import &quot;io/ioutil&quot;
  import &quot;log&quot;
  import &quot;encoding/json&quot;
  import &quot;time&quot;
  import &quot;strconv&quot;
  import &quot;os&quot;
  import &quot;./cmd&quot;
  import &quot;golang.org/x/sys/windows/svc/eventlog&quot;
  import &quot;fmt&quot;
  
  type myservice struct{}
  
  func (m *myservice) Execute(args []string, r &lt;-chan svc.ChangeRequest, changes chan&lt;- svc.Status) (ssec bool, errno uint32) {
      log.Println(&quot;Starting service&quot;)
      const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
      changes &lt;- svc.Status{State: svc.StartPending}
      changes &lt;- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
      StartService(r, changes)
      return
  }
  
  //RunService Runs the current application as a service.It will send the necessary flags to windows.
  func RunService(maintServiceName string) {
      //var elog eventlog
  
      elog, evtErr := eventlog.Open(maintServiceName)
      if evtErr != nil {
          return
      }
  
      defer elog.Close()
      log.Println(&quot;Running service&quot;)
      elog.Info(1, fmt.Sprintf(&quot;starting %s service&quot;, maintServiceName))
  
      run := svc.Run
      sererr := run(maintServiceName, &amp;myservice{})
      if sererr != nil {
          elog.Error(1, fmt.Sprintf(&quot;%s service failed: %v&quot;, maintServiceName, sererr))
      }
  }
  
  //StartService Starts the Service
  func StartService(r &lt;-chan svc.ChangeRequest, changes chan&lt;- svc.Status) {
      const cmdsAccepted = svc.AcceptStop | svc.AcceptShutdown | svc.AcceptPauseAndContinue
      jsonFile, err := os.Open(&quot;config.json&quot;)
      if err != nil {
          log.Fatalln(&quot;No configuration found&quot;)
      }
      byteVal, _ := ioutil.ReadAll(jsonFile)
      var result map[string]interface{}
      json.Unmarshal([]byte(byteVal), &amp;result)
      var serverURL = result[&quot;serverURL&quot;]
      var serviceName = result[&quot;serviceName&quot;]
      var intervalStr = result[&quot;interval&quot;].(string)
      var intervalInt, parseErr = strconv.ParseInt(intervalStr, 10, 32)
      if parseErr != nil {
          intervalInt = 60
      }
  
      log.Println(&quot;server Url &quot;, serverURL)
      log.Println(&quot;service name &quot;, serviceName)
  
      cmd.SetServerURL(serverURL.(string))
      cmd.SetServiceName(serviceName.(string))
      log.Println(&quot;Running Thread&quot;)
  
      go func() {
          for {
              log.Println(&quot;sleeping &quot;)
              time.Sleep(time.Duration(intervalInt) * time.Second)
              cmd.Connect()
          }
      }()
  
      select {
      case c := &lt;-r:
          if c.Cmd == svc.Stop || c.Cmd == svc.Shutdown {
              break
          }
          if c.Cmd == svc.Interrogate {
              changes &lt;- c.CurrentStatus
              time.Sleep(100 * time.Millisecond)
              changes &lt;- c.CurrentStatus
          }
          if c.Cmd == svc.Pause {
              changes &lt;- svc.Status{State: svc.Paused, Accepts: cmdsAccepted}
          }
          if c.Cmd == svc.Continue {
              changes &lt;- svc.Status{State: svc.Running, Accepts: cmdsAccepted}
          }
      }
  
  }
  </code></pre>
  <p>The application mostly runs without issues for mostly a day or two but stops after that without any errors. There are no logs after sleeping line in the log when it happens. Can I add anything to get more info about the service failure. What could be the problem here?</p>