mirror of
https://github.com/tailscale/tailscale.git
synced 2025-02-18 02:48:40 +00:00
magicsock: rate limit send error log messages
The x/time/rate dependency adds 24kb to tailscaled binary size. Signed-off-by: David Crawshaw <crawshaw@tailscale.com>
This commit is contained in:
parent
9cdaeac00a
commit
cc4afa775f
@ -24,6 +24,7 @@ import (
|
||||
"github.com/tailscale/wireguard-go/conn"
|
||||
"github.com/tailscale/wireguard-go/device"
|
||||
"github.com/tailscale/wireguard-go/wgcfg"
|
||||
"golang.org/x/time/rate"
|
||||
"tailscale.com/derp"
|
||||
"tailscale.com/derp/derphttp"
|
||||
"tailscale.com/stun"
|
||||
@ -41,6 +42,7 @@ type Conn struct {
|
||||
epFunc func(endpoints []string)
|
||||
logf func(format string, args ...interface{})
|
||||
donec chan struct{} // closed on Conn.Close
|
||||
sendLogLimit *rate.Limiter
|
||||
|
||||
epUpdateCtx context.Context // endpoint updater context
|
||||
epUpdateCancel func() // the func to cancel epUpdateCtx
|
||||
@ -138,6 +140,7 @@ func Listen(opts Options) (*Conn, error) {
|
||||
pconn: new(RebindingUDPConn),
|
||||
pconnPort: opts.Port,
|
||||
donec: make(chan struct{}),
|
||||
sendLogLimit: rate.NewLimiter(rate.Every(1*time.Minute), 1),
|
||||
stunServers: append([]string{}, opts.STUN...),
|
||||
startEpUpdate: make(chan struct{}, 1),
|
||||
epUpdateCtx: epUpdateCtx,
|
||||
@ -473,7 +476,7 @@ func (c *Conn) Send(b []byte, ep conn.Endpoint) error {
|
||||
} else if ret == nil {
|
||||
ret = err
|
||||
}
|
||||
if err != nil && addr != roamAddr {
|
||||
if err != nil && addr != roamAddr && c.sendLogLimit.Allow() {
|
||||
log.Printf("magicsock: Conn.Send(%v): %v", addr, err)
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user