Skip to content
This repository has been archived by the owner on Jul 22, 2024. It is now read-only.

Inaccurate use of mutexes #161

Merged
merged 1 commit into from
Feb 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions internal/proxy/healthchecker.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,8 +143,7 @@ func (h *RPCHealthchecker) CheckAndSetHealth() {
}

func (h *RPCHealthchecker) checkAndSetBlockNumberHealth() {
ctx := context.Background()
ctx, cancel := context.WithTimeout(ctx, h.config.Timeout)
ctx, cancel := context.WithTimeout(context.Background(), h.config.Timeout)
defer cancel()

// TODO
Expand Down Expand Up @@ -199,8 +198,8 @@ func (h *RPCHealthchecker) Stop(_ context.Context) error {
}

func (h *RPCHealthchecker) IsHealthy() bool {
h.mu.Lock()
defer h.mu.Unlock()
h.mu.RLock()
defer h.mu.RUnlock()

if h.isTainted {
// If the healthchecker is tainted, we always return unhealthy
Expand All @@ -211,28 +210,30 @@ func (h *RPCHealthchecker) IsHealthy() bool {
}

func (h *RPCHealthchecker) BlockNumber() uint64 {
h.mu.Lock()
defer h.mu.Unlock()
h.mu.RLock()
defer h.mu.RUnlock()

return h.blockNumber
}

func (h *RPCHealthchecker) GasLimit() uint64 {
h.mu.Lock()
defer h.mu.Unlock()
h.mu.RLock()
defer h.mu.RUnlock()

return h.gasLimit
}

func (h *RPCHealthchecker) IsTainted() bool {
h.mu.RLock()
defer h.mu.RUnlock()

return h.isTainted
}

func (h *RPCHealthchecker) Taint() {
h.mu.Lock()
defer h.mu.Unlock()

if h.isTainted {
return
}
Expand All @@ -257,6 +258,7 @@ func (h *RPCHealthchecker) Taint() {
func (h *RPCHealthchecker) RemoveTaint() {
h.mu.Lock()
defer h.mu.Unlock()

h.isTainted = false
h.lastTaintRemoval = time.Now()
zap.L().Info("RPC Taint Removed", zap.String("name", h.config.Name))
Expand Down
Loading