logtail: use link monitor to determine when to retry after upload failure

Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/1425/head
Brad Fitzpatrick 4 years ago committed by Brad Fitzpatrick
parent c3e5903b91
commit b4cf837d8a

@ -18,6 +18,7 @@ import (
"time" "time"
"tailscale.com/logtail/backoff" "tailscale.com/logtail/backoff"
"tailscale.com/net/interfaces"
tslogger "tailscale.com/types/logger" tslogger "tailscale.com/types/logger"
"tailscale.com/wgengine/monitor" "tailscale.com/wgengine/monitor"
) )
@ -287,6 +288,11 @@ func (l *Logger) uploading(ctx context.Context) {
} }
uploaded, err := l.upload(ctx, body, origlen) uploaded, err := l.upload(ctx, body, origlen)
if err != nil { if err != nil {
if !l.internetUp() {
fmt.Fprintf(l.stderr, "logtail: internet down; waiting\n")
l.awaitInternetUp(ctx)
continue
}
fmt.Fprintf(l.stderr, "logtail: upload: %v\n", err) fmt.Fprintf(l.stderr, "logtail: upload: %v\n", err)
} }
l.bo.BackOff(ctx, err) l.bo.BackOff(ctx, err)
@ -303,6 +309,34 @@ func (l *Logger) uploading(ctx context.Context) {
} }
} }
func (l *Logger) internetUp() bool {
if l.linkMonitor == nil {
// No way to tell, so assume it is.
return true
}
return l.linkMonitor.InterfaceState().AnyInterfaceUp()
}
func (l *Logger) awaitInternetUp(ctx context.Context) {
upc := make(chan bool, 1)
defer l.linkMonitor.RegisterChangeCallback(func(changed bool, st *interfaces.State) {
if st.AnyInterfaceUp() {
select {
case upc <- true:
default:
}
}
})()
if l.internetUp() {
return
}
select {
case <-upc:
fmt.Fprintf(l.stderr, "logtail: internet back up\n")
case <-ctx.Done():
}
}
// upload uploads body to the log server. // upload uploads body to the log server.
// origlen indicates the pre-compression body length. // origlen indicates the pre-compression body length.
// origlen of -1 indicates that the body is not compressed. // origlen of -1 indicates that the body is not compressed.

Loading…
Cancel
Save