Commit 980e7fd3 authored by Jordan Sissel's avatar Jordan Sissel

- make timeouts configurable

parent b43f1625
......@@ -17,7 +17,8 @@ type NetworkConfig struct {
SSLCertificate string `json:"ssl certificate"`
SSLKey string `json:"ssl key"`
SSLCA string `json:"ssl ca"`
Timeout time.Duration `json:timeout`
Timeout int64 `json:timeout`
timeout time.Duration
}
type FileConfig struct {
......@@ -51,9 +52,11 @@ func LoadConfig(path string) (config Config, err error) {
}
if config.Network.Timeout == 0 {
config.Network.Timeout = 5 * time.Second
config.Network.Timeout = 15
}
config.Network.timeout = time.Duration(config.Network.Timeout) * time.Second
//for _, fileconfig := range config.Files {
//if fileconfig.DeadTime == 0 {
//fileconfig.DeadTime = 24 * time.Hour
......
......@@ -49,6 +49,11 @@ func Publishv1(input chan []*FileEvent,
// Send buffer until we're successful...
oops := func(err error) {
// TODO(sissel): Track how frequently we timeout and reconnect. If we're
// timing out too frequently, there's really no point in timing out since
// basically everything is slow or down. We'll want to ratchet up the
// timeout value slowly until things improve, then ratchet it down once
// things seem healthy.
log.Printf("Socket error, will reconnect: %s\n", err)
time.Sleep(1 * time.Second)
socket.Close()
......@@ -58,7 +63,7 @@ func Publishv1(input chan []*FileEvent,
SendPayload: for {
// Abort if our whole request takes longer than the configured
// network timeout.
socket.SetDeadline(time.Now().Add(config.Timeout))
socket.SetDeadline(time.Now().Add(config.timeout))
// Set the window size to the length of this payload in events.
_, err = socket.Write([]byte("1W"))
......@@ -139,7 +144,7 @@ func connect(config *NetworkConfig) (socket *tls.Conn) {
address := config.Servers[rand.Int() % len(config.Servers)]
log.Printf("Connecting to %s\n", address)
tcpsocket, err := net.DialTimeout("tcp", address, config.Timeout)
tcpsocket, err := net.DialTimeout("tcp", address, config.timeout)
if err != nil {
log.Printf("Failure connecting to %s: %s\n", address, err)
time.Sleep(1 * time.Second)
......@@ -147,7 +152,7 @@ func connect(config *NetworkConfig) (socket *tls.Conn) {
}
socket = tls.Client(tcpsocket, &tlsconfig)
socket.SetDeadline(time.Now().Add(config.Timeout))
socket.SetDeadline(time.Now().Add(config.timeout))
err = socket.Handshake()
if err != nil {
log.Printf("Failed to tls handshake with %s %s\n", address, err)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment