source job: fix errnous log message when accept() on closed listener

This commit is contained in:
Christian Schwarz 2017-10-05 21:19:42 +02:00
parent c48069ce88
commit 40919d06c2

View File

@ -2,12 +2,13 @@ package cmd
import ( import (
"context" "context"
"io"
"time"
mapstructure "github.com/mitchellh/mapstructure" mapstructure "github.com/mitchellh/mapstructure"
"github.com/pkg/errors" "github.com/pkg/errors"
"github.com/zrepl/zrepl/rpc" "github.com/zrepl/zrepl/rpc"
"github.com/zrepl/zrepl/util" "github.com/zrepl/zrepl/util"
"io"
"time"
) )
type SourceJob struct { type SourceJob struct {
@ -128,7 +129,11 @@ func (j *SourceJob) serve(ctx context.Context) {
return return
} }
rwcChan := make(chan io.ReadWriteCloser) type rwcChanMsg struct {
rwc io.ReadWriteCloser
err error
}
rwcChan := make(chan rwcChanMsg)
// Serve connections until interrupted or error // Serve connections until interrupted or error
outer: outer:
@ -137,22 +142,23 @@ outer:
go func() { go func() {
rwc, err := listener.Accept() rwc, err := listener.Accept()
if err != nil { if err != nil {
log.WithError(err).Error("error accepting connection") rwcChan <- rwcChanMsg{rwc, err}
close(rwcChan) close(rwcChan)
return return
} }
rwcChan <- rwc rwcChan <- rwcChanMsg{rwc, err}
}() }()
select { select {
case rwc, notClosed := <-rwcChan: case rwcMsg := <-rwcChan:
if !notClosed { if rwcMsg.err != nil {
break outer // closed because of accept error log.WithError(err).Error("error accepting connection")
break outer
} }
rwc, err := util.NewReadWriteCloserLogger(rwc, j.Debug.Conn.ReadDump, j.Debug.Conn.WriteDump) rwc, err := util.NewReadWriteCloserLogger(rwcMsg.rwc, j.Debug.Conn.ReadDump, j.Debug.Conn.WriteDump)
if err != nil { if err != nil {
panic(err) panic(err)
} }