Reconnect after waiting too long for request
This commit is contained in:
@@ -45,7 +45,35 @@ func startSingleConnection(connectionId int) {
|
||||
}
|
||||
|
||||
for {
|
||||
encodedRequestMessage, err := bufio.NewReader(conn).ReadString('\n')
|
||||
timeout := make(chan bool, 1)
|
||||
go func() {
|
||||
time.Sleep(time.Duration(c.ClientConfig.WaitingTimeout) * time.Second)
|
||||
timeout <- true
|
||||
}()
|
||||
|
||||
requestChann := make(chan bool, 1)
|
||||
var err error
|
||||
var encodedRequestMessage string
|
||||
go func() {
|
||||
encodedRequestMessage, err = bufio.NewReader(conn).ReadString('\n')
|
||||
requestChann <- true
|
||||
}()
|
||||
|
||||
timeoutConnection := false
|
||||
|
||||
select {
|
||||
case <-requestChann:
|
||||
timeoutConnection = false
|
||||
case <-timeout:
|
||||
timeoutConnection = true
|
||||
}
|
||||
|
||||
if timeoutConnection {
|
||||
log.Printf("(%d) Server not sending requests for too long, closing connection\n", connectionId)
|
||||
_ = conn.Close()
|
||||
break
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Printf("(%d) Error receiving request from load balancer server : %s\n", connectionId, err)
|
||||
_ = conn.Close()
|
||||
|
||||
Reference in New Issue
Block a user