mirror of
https://github.com/fluencelabs/tendermint
synced 2025-06-17 07:01:20 +00:00
privval: set deadline in readMsg (#2548)
* privval: set deadline in readMsg * fixes from review
This commit is contained in:
@ -18,11 +18,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
const (
|
const (
|
||||||
defaultAcceptDeadlineSeconds = 3
|
defaultAcceptDeadlineSeconds = 30 // tendermint waits this long for remote val to connect
|
||||||
defaultConnDeadlineSeconds = 3
|
defaultConnDeadlineSeconds = 3 // must be set before each read
|
||||||
defaultConnHeartBeatSeconds = 30
|
defaultConnHeartBeatSeconds = 30 // tcp keep-alive period
|
||||||
defaultConnWaitSeconds = 60
|
defaultConnWaitSeconds = 60 // XXX: is this redundant with the accept deadline?
|
||||||
defaultDialRetries = 10
|
defaultDialRetries = 10 // try to connect to tendermint this many times
|
||||||
)
|
)
|
||||||
|
|
||||||
// Socket errors.
|
// Socket errors.
|
||||||
@ -33,12 +33,6 @@ var (
|
|||||||
ErrUnexpectedResponse = errors.New("received unexpected response")
|
ErrUnexpectedResponse = errors.New("received unexpected response")
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
|
||||||
acceptDeadline = time.Second * defaultAcceptDeadlineSeconds
|
|
||||||
connDeadline = time.Second * defaultConnDeadlineSeconds
|
|
||||||
connHeartbeat = time.Second * defaultConnHeartBeatSeconds
|
|
||||||
)
|
|
||||||
|
|
||||||
// SocketPVOption sets an optional parameter on the SocketPV.
|
// SocketPVOption sets an optional parameter on the SocketPV.
|
||||||
type SocketPVOption func(*SocketPV)
|
type SocketPVOption func(*SocketPV)
|
||||||
|
|
||||||
@ -93,9 +87,9 @@ func NewSocketPV(
|
|||||||
) *SocketPV {
|
) *SocketPV {
|
||||||
sc := &SocketPV{
|
sc := &SocketPV{
|
||||||
addr: socketAddr,
|
addr: socketAddr,
|
||||||
acceptDeadline: acceptDeadline,
|
acceptDeadline: time.Second * defaultAcceptDeadlineSeconds,
|
||||||
connDeadline: connDeadline,
|
connDeadline: time.Second * defaultConnDeadlineSeconds,
|
||||||
connHeartbeat: connHeartbeat,
|
connHeartbeat: time.Second * defaultConnHeartBeatSeconds,
|
||||||
connWaitTimeout: time.Second * defaultConnWaitSeconds,
|
connWaitTimeout: time.Second * defaultConnWaitSeconds,
|
||||||
privKey: privKey,
|
privKey: privKey,
|
||||||
}
|
}
|
||||||
@ -441,7 +435,7 @@ func (rs *RemoteSigner) connect() (net.Conn, error) {
|
|||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if err := conn.SetDeadline(time.Now().Add(connDeadline)); err != nil {
|
if err := conn.SetDeadline(time.Now().Add(time.Second * defaultConnDeadlineSeconds)); err != nil {
|
||||||
err = cmn.ErrorWrap(err, "setting connection timeout failed")
|
err = cmn.ErrorWrap(err, "setting connection timeout failed")
|
||||||
rs.Logger.Error(
|
rs.Logger.Error(
|
||||||
"connect",
|
"connect",
|
||||||
@ -587,6 +581,14 @@ type RemoteSignerError struct {
|
|||||||
|
|
||||||
func readMsg(r io.Reader) (msg SocketPVMsg, err error) {
|
func readMsg(r io.Reader) (msg SocketPVMsg, err error) {
|
||||||
const maxSocketPVMsgSize = 1024 * 10
|
const maxSocketPVMsgSize = 1024 * 10
|
||||||
|
|
||||||
|
// set deadline before trying to read
|
||||||
|
conn := r.(net.Conn)
|
||||||
|
if err := conn.SetDeadline(time.Now().Add(time.Second * defaultConnDeadlineSeconds)); err != nil {
|
||||||
|
err = cmn.ErrorWrap(err, "setting connection timeout failed in readMsg")
|
||||||
|
return msg, err
|
||||||
|
}
|
||||||
|
|
||||||
_, err = cdc.UnmarshalBinaryReader(r, &msg, maxSocketPVMsgSize)
|
_, err = cdc.UnmarshalBinaryReader(r, &msg, maxSocketPVMsgSize)
|
||||||
if _, ok := err.(timeoutError); ok {
|
if _, ok := err.(timeoutError); ok {
|
||||||
err = cmn.ErrorWrap(ErrConnTimeout, err.Error())
|
err = cmn.ErrorWrap(ErrConnTimeout, err.Error())
|
||||||
|
Reference in New Issue
Block a user