This is an automated email from the ASF dual-hosted git repository.
hsluoyz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/casbin-gateway.git
The following commit(s) were added to refs/heads/master by this push:
new e550ef7 fix(agents): name agent egress hosts that getaddrinfo cached
e550ef7 is described below
commit e550ef78dfee1eb6247543a95002d4050f202aa6
Author: Yang Luo <[email protected]>
AuthorDate: Fri Sep 25 00:40:11 2026 +0800
fix(agents): name agent egress hosts that getaddrinfo cached
---
agentegress/egress.go | 7 +++++--
agentegress/sample_windows.go | 7 +++++--
2 files changed, 10 insertions(+), 4 deletions(-)
diff --git a/agentegress/egress.go b/agentegress/egress.go
index 93811de..74815f1 100644
--- a/agentegress/egress.go
+++ b/agentegress/egress.go
@@ -35,6 +35,7 @@ import (
const (
sampleInterval = 500 * time.Millisecond
pidInterval = 5 * time.Second
+ cacheInterval = 5 * time.Second
// A burst is this much sent to one destination within burstWindow.
burstBytes = 5 << 20
burstWindow = time.Minute
@@ -434,7 +435,9 @@ func evictOldest(dests map[string]*destination) {
// resolve names the remote addresses the DNS cache knows, going back to the
// cache for a new address at most once a second and giving up on one after a
-// few tries: an agent that connects by address has no name to find.
+// few tries: an agent that connects by address has no name to find. The cache
+// is also read every few seconds regardless, because a name with a short TTL
+// leaves it while the agent keeps connecting to its addresses.
func (w *watcher) resolve(sockets []socket, now time.Time) {
var missing []netip.Addr
for _, sock := range sockets {
@@ -453,7 +456,7 @@ func (w *watcher) resolve(sockets []socket, now time.Time) {
}
missing = append(missing, addr)
}
- if len(missing) == 0 || now.Sub(w.lookedUp) < time.Second {
+ if since := now.Sub(w.lookedUp); since < time.Second || (len(missing)
== 0 && since < cacheInterval) {
return
}
w.lookedUp = now
diff --git a/agentegress/sample_windows.go b/agentegress/sample_windows.go
index fbdaa47..d38699d 100644
--- a/agentegress/sample_windows.go
+++ b/agentegress/sample_windows.go
@@ -48,7 +48,10 @@ const (
dnsTypeA = 1
dnsTypeCname = 5
dnsTypeAAAA = 28
- dnsQueryNoWire = 0x10
+ // DNS_QUERY_NO_WIRE_QUERY plus the undocumented bit ipconfig
/displaydns
+ // passes. Without it the cache hides what getaddrinfo put there, which
is
+ // every name Node and Electron resolve.
+ dnsQueryCacheOnly = 0x8010
)
// MIB_TCPROW and MIB_TCP6ROW: what the EStats calls take.
@@ -231,7 +234,7 @@ func cachedNames() map[netip.Addr]string {
func cachedAddrs(name string, kind uint16) ([]netip.Addr, bool) {
var records *windows.DNSRecord
- if windows.DnsQuery(name, kind, dnsQueryNoWire, nil, &records, nil) !=
nil {
+ if windows.DnsQuery(name, kind, dnsQueryCacheOnly, nil, &records, nil)
!= nil {
return nil, false
}
defer windows.DnsRecordListFree(records, 1)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]