From a9a2a8ed95786f303863877fbf301f50bccbbaa7 Mon Sep 17 00:00:00 2001 From: Adam Fisk Date: Thu, 14 May 2026 15:38:45 -0600 Subject: [PATCH] peer: route the peer-box sing-box logger into radiance's slog MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The second sing-box instance the peer client spins up was constructed with a plain box.BaseContext() and no sing-box log factory registered. That means router / dial / outbound errors from the peer-box landed on the box's default stderr logger and never reached lantern.log — which made the recent SmC verify-failure incident (FD #174614) unnecessarily hard to triage. The verifier's CONNECT handler returned within 17 ms with no error log anywhere in the lantern logs; the "why did api.iantem.io fail to dial?" answer was just silently swallowed. Mirror what vpn/tunnel.go:141-142 already does for the main tunnel's box — register lblog.NewFactory(slog.Default().Handler()) as the sblog.Factory on the peer-box's context before NewServiceWithContext. sing-box logger output now flows through radiance's slog and into lantern.log alongside everything else. Co-Authored-By: Claude Opus 4.7 (1M context) --- peer/peer.go | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/peer/peer.go b/peer/peer.go index 60954854..a30032f9 100644 --- a/peer/peer.go +++ b/peer/peer.go @@ -13,8 +13,11 @@ import ( "time" "github.com/sagernet/sing-box/experimental/libbox" + sblog "github.com/sagernet/sing-box/log" + "github.com/sagernet/sing/service" box "github.com/getlantern/lantern-box" + lblog "github.com/getlantern/lantern-box/log" "github.com/getlantern/lantern-box/tracker/peerconn" "github.com/getlantern/radiance/common/settings" "github.com/getlantern/radiance/events" @@ -613,7 +616,17 @@ func pickInternalPort() uint16 { // here are scoped to this peer's box instance so the two coexist // without stomping on each other. func defaultBuildBoxService(_ context.Context, options string) (boxService, error) { - bs, err := libbox.NewServiceWithContext(box.BaseContext(), options, nil) + // Wire the peer's sing-box logger into radiance's slog so router / + // dial / outbound errors from this second box instance reach the + // same lantern.log as everything else. Without this the box's + // default stderr-only logger silently swallows the most useful + // signal — e.g. "why did api.iantem.io fail to dial?" during a + // peer-share verify failure — which made FD #174614 unnecessarily + // hard to triage. Mirrors vpn/tunnel.go's registration for the + // main tunnel's box. + ctx := box.BaseContext() + service.MustRegister[sblog.Factory](ctx, lblog.NewFactory(slog.Default().Handler())) + bs, err := libbox.NewServiceWithContext(ctx, options, nil) if err != nil { return nil, fmt.Errorf("libbox.NewServiceWithContext: %w", err) }