diff --git a/.travis.yml b/.travis.yml index 7915327..2adce4a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,5 +6,3 @@ install: - make deps script: - make test -after_success: - - bash <(curl -s https://codecov.io/bash) diff --git a/Makefile b/Makefile index 0ccc19c..bd2fbfd 100644 --- a/Makefile +++ b/Makefile @@ -10,8 +10,4 @@ clean: deps: go mod download test: - echo "" > coverage.txt - for d in $(shell go list ./...); do \ - go test -race -v -coverprofile=profile.out -covermode=atomic $$d || exit 1; \ - [ -f profile.out ] && cat profile.out >> coverage.txt && rm profile.out; \ - done + go test -race -cover ./... diff --git a/server.go b/server.go index 48dd15a..b2e30d0 100644 --- a/server.go +++ b/server.go @@ -14,6 +14,7 @@ var mutex sync.Mutex // Server server representation type Server struct { + sync.RWMutex name string health *ServerHealth serverSettings ServerSettings @@ -70,13 +71,22 @@ func (s *Server) CheckHealth(traceOn bool, logger Logger) { var secondsBehindMaster, openConnections, runningConnections *int // prevent concurrently checks on same server (slow queries/network) - if s.isChecking { + s.RLock() + checking := s.isChecking + s.RUnlock() + + if checking { return } + s.Lock() s.isChecking = true + s.Unlock() + defer func() { + s.Lock() s.isChecking = false + s.Unlock() }() if err := s.connectReadUser(traceOn, logger); err != nil {