ping often
All checks were successful
Build and Publish / BuildAndDeploy (push) Successful in 1m45s

This commit is contained in:
matst80
2024-11-09 20:22:42 +01:00
parent f1c3fa8240
commit 9619ae1000

View File

@@ -85,6 +85,27 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced
remotes: make([]*RemoteHost, 0),
remoteIndex: make(map[CartId]*RemoteGrainPool),
}
pingTimer := time.NewTicker(time.Second)
go func() {
for {
<-pingTimer.C
for i, r := range pool.remotes {
err := DoPing(r.connection)
if err != nil {
r.MissedPings++
log.Printf("Error pinging remote %s: %v\n, missed pings: %d", r.Host, err, r.MissedPings)
if r.MissedPings > 3 {
log.Printf("Removing remote %s\n", r.Host)
pool.remotes = append(pool.remotes[:i], pool.remotes[i+1:]...)
}
} else {
r.MissedPings = 0
}
}
}
}()
if d != nil {
discoveryTimer := time.NewTicker(time.Second * 5)
go func() {
@@ -127,21 +148,7 @@ func NewSyncedPool(local *GrainLocalPool, hostname string, d Discovery) (*Synced
log.Printf("Error adding undiscovered remote %s: %v\n", h, err)
}
}
for i, r := range pool.remotes {
err := DoPing(r.connection)
if err != nil {
r.MissedPings++
log.Printf("Error pinging remote %s: %v\n, missed pings: %d", r.Host, err, r.MissedPings)
if r.MissedPings > 3 {
log.Printf("Removing remote %s\n", r.Host)
pool.remotes = append(pool.remotes[:i], pool.remotes[i+1:]...)
}
} else {
r.MissedPings = 0
}
}
}()
}
go func() {