appleboy / appleboy/loadbalancer-algorithms

Weighted algorithm returns error after removing server

Open
#13 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Go
Stars
46
Forks
8
PR merge metrics
No merged PRs in 30d

Description

Hi appleboy

I am using this project as a package to build an actual loadbalancer. I implemented a health check which removes failing servers from the loadbalancer. The [remove server](https://github.com/Vickysomtee/loadbalancer-algorithms/blob/c0e25a94ef6dba5880f4bc65ae86772343bed168/weighted/weighted.go#L112) function actually removes a server but still returns the error `server not found`. I can't really figure the reason

Below is my implementation

```
func healthCheck(server *Server, healthCheckInterval time.Duration) {
for range time.Tick(healthCheckInterval) {
res, err := http.Head(server.HealthCheckUrl)
mutex.Lock()
if err != nil || res.StatusCode != http.StatusOK {
fmt.Printf("%s is down\n", server.Url)
server.IsHealthy = false
err := balance.RemoveServer(server.Host)
if err != nil { // This error is not nil even after removing the server
fmt.Printf("Could not remove unhealthy server %s: %s", server.Url, err)
}
} else {
server.IsHealthy = true
}
mutex.Unlock()
}
}

```

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in weighted/weighted.go at the remove server function linked in the issue, then compare its behavior with the healthCheck example that calls balance.RemoveServer(server.Host). Reproduce the removal path and determine why the server is removed while the function still returns “server not found”; done means the failing-server removal reports success consistently.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
backend, networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.