Skip to content

Commit

Permalink
Merge pull request #16 from bobrik/timeouts
Browse files Browse the repository at this point in the history
5 second timeout for balancer and mesos communication
  • Loading branch information
bobrik committed Jul 28, 2015
2 parents e5732f3 + 25bd7ff commit a24bfbb
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
7 changes: 6 additions & 1 deletion balancer.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
)

type Balancer struct {
Expand All @@ -30,8 +31,12 @@ func (b Balancer) update(name string, apps Apps, state State) error {
return err
}

c := http.Client{
Timeout: time.Second * 5,
}

u := fmt.Sprintf("http://%s:%d/state/%s", b.Host, b.Port, name)
resp, err := http.Post(u, "application/json", bytes.NewReader(body))
resp, err := c.Post(u, "application/json", bytes.NewReader(body))
if err != nil {
return err
}
Expand Down
7 changes: 6 additions & 1 deletion mesos.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"strconv"
"strings"
"time"
)

var ErrNoMesosMaster = errors.New("mesos master not found")
Expand Down Expand Up @@ -91,12 +92,16 @@ func (mp *mesosPorts) UnmarshalJSON(b []byte) error {
type MesosDiscoverer struct {
masters []string
balancer string
client http.Client
}

func NewMesosDiscoverer(masters []string, balancer string) MesosDiscoverer {
return MesosDiscoverer{
masters: masters,
balancer: balancer,
client: http.Client{
Timeout: time.Second * 5,
},
}
}

Expand Down Expand Up @@ -172,7 +177,7 @@ func (m MesosDiscoverer) tasks() ([]refinedMesosTask, error) {
s := mesosState{}

for _, master := range m.masters {
resp, err := http.Get(master + "/state.json")
resp, err := m.client.Get(master + "/state.json")
if err != nil {
log.Printf("error fetching state from %s: %s\n", master, err)
continue
Expand Down

0 comments on commit a24bfbb

Please sign in to comment.