diff --git a/cmd/syncthing/main.go b/cmd/syncthing/main.go index c34156d70..8b29fdc0d 100644 --- a/cmd/syncthing/main.go +++ b/cmd/syncthing/main.go @@ -1054,7 +1054,7 @@ func (m migratingAPI) Serve(ctx context.Context) error { srv := &http.Server{ Addr: m.addr, Handler: http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - w.Header().Set("Content-Type", "text/plain") + w.Header().Set("Content-Type", "text/plain; charset=utf-8") w.Write([]byte("*** Database migration in progress ***\n\n")) for _, line := range slogutil.GlobalRecorder.Since(time.Time{}) { _, _ = line.WriteTo(w, slogutil.DefaultLineFormat) diff --git a/lib/pmp/debug.go b/lib/pmp/debug.go index 3a76691c5..a1cee6938 100644 --- a/lib/pmp/debug.go +++ b/lib/pmp/debug.go @@ -8,4 +8,4 @@ package pmp import "github.com/syncthing/syncthing/internal/slogutil" -var l = slogutil.NewAdapter("NAT-PMP discovery and port mapping") +func init() { slogutil.RegisterPackage("NAT-PMP discovery and port mapping") } diff --git a/lib/pmp/pmp.go b/lib/pmp/pmp.go index 3b7ad8d46..035896fdd 100644 --- a/lib/pmp/pmp.go +++ b/lib/pmp/pmp.go @@ -16,6 +16,7 @@ import ( natpmp "github.com/jackpal/go-nat-pmp" + "github.com/syncthing/syncthing/internal/slogutil" "github.com/syncthing/syncthing/lib/nat" "github.com/syncthing/syncthing/lib/netutil" "github.com/syncthing/syncthing/lib/osutil" @@ -34,14 +35,14 @@ func Discover(ctx context.Context, renewal, timeout time.Duration) []nat.Device return err }) if err != nil { - l.Debugln("Failed to discover gateway", err) + slog.DebugContext(ctx, "Failed to discover gateway", slogutil.Error(err)) return nil } if ip == nil || ip.IsUnspecified() { return nil } - l.Debugln("Discovered gateway at", ip) + slog.DebugContext(ctx, "Discovered gateway", "ip", ip) c := natpmp.NewClientWithTimeout(ip, timeout) // Try contacting the gateway, if it does not respond, assume it does not @@ -51,13 +52,8 @@ func Discover(ctx context.Context, renewal, timeout time.Duration) []nat.Device return ierr }) if err != nil { - if errors.Is(err, context.Canceled) { - return nil - } - if strings.Contains(err.Error(), "Timed out") { - slog.Debug("Timeout trying to get external address, assume no NAT-PMP available") - return nil - } + slog.DebugContext(ctx, "Failed to get external address", slogutil.Error(err)) + return nil } var localIP net.IP @@ -69,7 +65,7 @@ func Discover(ctx context.Context, renewal, timeout time.Duration) []nat.Device conn.Close() localIP, err = osutil.IPFromAddr(conn.LocalAddr()) if localIP == nil { - l.Debugln("Failed to lookup local IP", err) + slog.DebugContext(ctx, "Failed to lookup local IP", slogutil.Error(err)) } } diff --git a/lib/upgrade/upgrade_supported.go b/lib/upgrade/upgrade_supported.go index d64dd3b10..fc236af52 100644 --- a/lib/upgrade/upgrade_supported.go +++ b/lib/upgrade/upgrade_supported.go @@ -101,6 +101,7 @@ func FetchLatestReleases(releasesURL, current string) []Release { slog.Warn("Failed to fetch latest release information", slogutil.Error(err)) return nil } + defer resp.Body.Close() if resp.StatusCode > 299 { slog.Warn("Failed to fetch latest release information", slogutil.Error(resp.Status)) return nil @@ -111,7 +112,6 @@ func FetchLatestReleases(releasesURL, current string) []Release { if err != nil { slog.Warn("Failed to decode latest release information", slogutil.Error(err)) } - resp.Body.Close() return rels }