Skip to content

Commit f7c9b16

Browse files
committed
Log errors (as traces)
1 parent 4eca197 commit f7c9b16

File tree

1 file changed

+32
-7
lines changed

1 file changed

+32
-7
lines changed

plugin/scheduler.go

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,43 @@ func (p *Plugin) PeriodicInvalidator() {
2121
p.Logger.Trace("Got proxies from GatewayD", "proxies", proxies)
2222

2323
// Get all the client keys and delete the ones that are not valid.
24+
// TODO: use scan instead of keys.
2425
for _, address := range p.RedisClient.Keys(context.Background(), "*:*").Val() {
25-
if validateAddressPort(address) || validateHostPort(address) {
26-
// If the connection is busy, it is not safe to delete the key.
27-
if isBusy(proxies, address) {
28-
p.Logger.Trace("Skipping connection because it is busy", "address", address)
26+
valid := false
27+
28+
// Validate the address if the address is an IP address.
29+
if ok, err := validateAddressPort(address); ok && err == nil {
30+
valid = true
31+
} else {
32+
p.Logger.Trace(
33+
"Skipping connection because it is invalid", "address", address, "error", err)
34+
}
35+
36+
if !valid {
37+
// Validate the address if the address is a hostname.
38+
if ok, err := validateHostPort(address); ok && err == nil {
39+
valid = true
40+
} else {
41+
p.Logger.Trace(
42+
"Skipping connection because it is invalid", "address", address, "error", err)
2943
continue
3044
}
45+
}
3146

32-
p.RedisClient.Del(context.Background(), address)
33-
p.Logger.Trace("Deleted address", "address", address)
34-
CacheDeletesCounter.Inc()
47+
// If the address is not valid, skip it.
48+
if !valid {
49+
continue
3550
}
51+
52+
// If the connection is busy (a client is connected), it is not safe to delete the key.
53+
if isBusy(proxies, address) {
54+
p.Logger.Trace("Skipping connection because it is busy", "address", address)
55+
continue
56+
}
57+
58+
p.RedisClient.Del(context.Background(), address)
59+
p.Logger.Trace("Deleted stale address", "address", address)
60+
CacheDeletesCounter.Inc()
3661
}
3762
}); err != nil {
3863
p.Logger.Error("Failed to start periodic invalidator",

0 commit comments

Comments
 (0)