Skip to content

Commit

Permalink
add 1s-timeout for node-2-node connection
Browse files Browse the repository at this point in the history
  • Loading branch information
ineiti committed Aug 24, 2021
1 parent dd9190c commit f791225
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 12 deletions.
5 changes: 3 additions & 2 deletions network/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import (
// received. sends and connects will timeout using this timeout as well.
var timeout = 1 * time.Minute

// dialTimeout is the timeout for connecting to an end point.
var dialTimeout = 1 * time.Minute
// dialTimeout is the timeout for connecting to an end point. This is much
// lower than the normal read timeout.
var dialTimeout = 1 * time.Second

// Global lock for 'timeout' (because also used in 'tcp_test.go')
// Using a 'RWMutex' to be as efficient as possible, because it will be used
Expand Down
3 changes: 2 additions & 1 deletion network/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,8 @@ func NewTLSConn(us *ServerIdentity, them *ServerIdentity, suite Suite) (conn *TC
for i := 1; i <= MaxRetryConnect; i++ {
var c net.Conn
cfg.ServerName = string(nonce)
c, err = tls.DialWithDialer(&net.Dialer{Timeout: timeout}, "tcp", netAddr, cfg)
c, err = tls.DialWithDialer(&net.Dialer{Timeout: dialTimeout}, "tcp", netAddr,
cfg)
if err == nil {
conn = &TCPConn{
conn: c,
Expand Down
18 changes: 9 additions & 9 deletions websocket_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,11 @@ type Client struct {
// if not nil, use TLS
TLSClientConfig *tls.Config
// whether to keep the connection
keep bool
rx uint64
tx uint64
keep bool
rx uint64
tx uint64
// How long to wait for a reply
ReadTimeout time.Duration
ReadTimeout time.Duration
// How long to wait to open a connection
HandshakeTimeout time.Duration
sync.Mutex
Expand All @@ -45,11 +45,11 @@ type Client struct {
// connection will be started, until Close is called.
func NewClient(suite network.Suite, s string) *Client {
return &Client{
service: s,
connections: make(map[destination]*websocket.Conn),
connectionsLock: make(map[destination]*sync.Mutex),
suite: suite,
ReadTimeout: time.Second * 60,
service: s,
connections: make(map[destination]*websocket.Conn),
connectionsLock: make(map[destination]*sync.Mutex),
suite: suite,
ReadTimeout: time.Second * 60,
HandshakeTimeout: time.Second * 5,
}
}
Expand Down

0 comments on commit f791225

Please sign in to comment.