From 1853812da2bb30c051a9d43cb818b2be9aa652cd Mon Sep 17 00:00:00 2001 From: Paul Dix Date: Mon, 24 Feb 2014 13:52:46 -0500 Subject: [PATCH] Make an error on request to another server send the message down the response channel (non-blocking) so that go routines monitoring the channel and not the method return can stop. --- src/cluster/cluster_server.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/cluster/cluster_server.go b/src/cluster/cluster_server.go index 4fc4388340..e2c1722a06 100644 --- a/src/cluster/cluster_server.go +++ b/src/cluster/cluster_server.go @@ -12,7 +12,7 @@ import ( const ( DEFAULT_BACKOFF = time.Second MAX_BACKOFF = 10 * time.Second - HEARTBEAT_TIMEOUT = 200 * time.Millisecond + HEARTBEAT_TIMEOUT = 100 * time.Millisecond ) type ClusterServer struct { @@ -93,6 +93,11 @@ func (self *ClusterServer) MakeRequest(request *protocol.Request, responseStream err := self.connection.MakeRequest(request, responseStream) if err != nil { self.isUp = false + message := err.Error() + select { + case responseStream <- &protocol.Response{Type: &endStreamResponse, ErrorMessage: &message}: + default: + } } return err } @@ -156,14 +161,14 @@ func (self *ClusterServer) getHeartbeatResponse(responseChan <-chan *protocol.Re select { case response := <-responseChan: if response.ErrorMessage != nil { - return fmt.Errorf("Server returned error to heartbeat: %s", *response.ErrorMessage) + return fmt.Errorf("Server %d returned error to heartbeat: %s", self.Id, *response.ErrorMessage) } if *response.Type != protocol.Response_HEARTBEAT { return fmt.Errorf("Server returned a non heartbeat response") } case <-time.After(HEARTBEAT_TIMEOUT): - return fmt.Errorf("Server failed to return heartbeat in 100ms", "") + return fmt.Errorf("Server failed to return heartbeat in 100ms: %d", self.Id) } return nil