atc: fix syslog leaking goroutines
@@ -5,6 +5,7 @@ import (
"encoding/json"
"time"
+ "code.cloudfoundry.org/lager"
"code.cloudfoundry.org/lager/lagerctx"
"github.com/concourse/concourse/atc/db"
"github.com/concourse/concourse/atc/event"
@@ -49,15 +50,30 @@ func (d *drainer) Run(ctx context.Context) error {
logger.Error("Syslog drainer connecting to server error.", err)
return err
}
- defer syslog.Close()
+
+ // ignore any errors coming from syslog.Close()
+ defer db.Close(syslog)
for _, build := range builds {
+ err := d.drainBuild(logger, build, syslog)
+ if err != nil {
+ return err
+ }
+ }
+ }
+ return nil
+}
+
+func (d *drainer) drainBuild(logger lager.Logger, build db.Build, syslog *Syslog) error {
events, err := build.Events(0)
if err != nil {
logger.Error("Syslog drainer getting build events error.", err)
return err
}
+ // ignore any errors coming from events.Close()
+ defer db.Close(events)
+
for {
ev, err := events.Next()
if err != nil {
@@ -80,6 +96,7 @@ func (d *drainer) Run(ctx context.Context) error {
payload := log.Payload
tag := build.TeamName() + "/" + build.PipelineName() + "/" + build.JobName() + "/" + build.Name() + "/" + string(log.Origin.ID)
+
err = syslog.Write(d.hostname, tag, time.Unix(log.Time, 0), payload)
if err != nil {
logger.Error("Syslog drainer sending to server error.", err)
@@ -93,7 +110,6 @@ func (d *drainer) Run(ctx context.Context) error {
logger.Error("Syslog drainer setting drained on build error.", err)
return err
}
- }
- }
+
return nil
}
