Merge branch 'release/v0.28.0' into release/v0.28.0

This commit is contained in:
Thane Thomson 2019-01-15 17:58:33 +02:00 committed by GitHub
commit 308b7e3bbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 32 deletions

View File

@ -45,7 +45,7 @@ func main() {
dialer = privval.DialTCPFn(address, connTimeout, ed25519.GenPrivKey()) dialer = privval.DialTCPFn(address, connTimeout, ed25519.GenPrivKey())
default: default:
logger.Error("Unknown protocol", "protocol", protocol) logger.Error("Unknown protocol", "protocol", protocol)
return os.Exit(1)
} }
rs := privval.NewRemoteSigner(logger, *chainID, pv, dialer) rs := privval.NewRemoteSigner(logger, *chainID, pv, dialer)

View File

@ -901,7 +901,7 @@ func createAndStartPrivValidatorSocketClient(
pvsc := privval.NewSocketVal(logger.With("module", "privval"), listener) pvsc := privval.NewSocketVal(logger.With("module", "privval"), listener)
if err := pvsc.Start(); err != nil { if err := pvsc.Start(); err != nil {
return nil, errors.Wrap(err, "failed to start") return nil, errors.Wrap(err, "failed to start private validator")
} }
return pvsc, nil return pvsc, nil

View File

@ -191,19 +191,19 @@ func (sc *SocketVal) OnStop() {
// connection is closed in OnStop. // connection is closed in OnStop.
// returns true if the listener is closed // returns true if the listener is closed
// (ie. it returns a nil conn). // (ie. it returns a nil conn).
func (sc *SocketVal) reset() (bool, error) { func (sc *SocketVal) reset() (closed bool, err error) {
sc.mtx.Lock() sc.mtx.Lock()
defer sc.mtx.Unlock() defer sc.mtx.Unlock()
// first check if the conn already exists and close it. // first check if the conn already exists and close it.
if sc.signer != nil { if sc.signer != nil {
if err := sc.signer.Close(); err != nil { if err := sc.signer.Close(); err != nil {
sc.Logger.Error("error closing connection", "err", err) sc.Logger.Error("error closing socket val connection during reset", "err", err)
} }
} }
// wait for a new conn // wait for a new conn
conn, err := sc.waitConnection() conn, err := sc.acceptConnection()
if err != nil { if err != nil {
return false, err return false, err
} }
@ -224,6 +224,8 @@ func (sc *SocketVal) reset() (bool, error) {
return false, nil return false, nil
} }
// Attempt to accept a connection.
// Times out after the listener's acceptDeadline
func (sc *SocketVal) acceptConnection() (net.Conn, error) { func (sc *SocketVal) acceptConnection() (net.Conn, error) {
conn, err := sc.listener.Accept() conn, err := sc.listener.Accept()
if err != nil { if err != nil {
@ -231,33 +233,6 @@ func (sc *SocketVal) acceptConnection() (net.Conn, error) {
return nil, nil // Ignore error from listener closing. return nil, nil // Ignore error from listener closing.
} }
return nil, err return nil, err
} }
return conn, nil return conn, nil
} }
// waitConnection uses the configured wait timeout to error if no external
// process connects in the time period.
func (sc *SocketVal) waitConnection() (net.Conn, error) {
var (
connc = make(chan net.Conn, 1)
errc = make(chan error, 1)
)
go func(connc chan<- net.Conn, errc chan<- error) {
conn, err := sc.acceptConnection()
if err != nil {
errc <- err
return
}
connc <- conn
}(connc, errc)
select {
case conn := <-connc:
return conn, nil
case err := <-errc:
return nil, err
}
}