From f7f9a7ae2018c4f16641e9a1281055ba5fa6fd8b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=B8=96=E7=95=8C?= Date: Mon, 10 Apr 2023 08:48:58 +0800 Subject: [PATCH] Fix write log to stderr --- experimental/libbox/command_log.go | 2 +- experimental/libbox/command_server.go | 5 ++++- experimental/libbox/command_status.go | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/experimental/libbox/command_log.go b/experimental/libbox/command_log.go index 851f0ed3..b70e9884 100644 --- a/experimental/libbox/command_log.go +++ b/experimental/libbox/command_log.go @@ -63,7 +63,7 @@ func (s *CommandServer) handleLogConn(conn net.Conn) error { for { select { case <-ctx.Done(): - return nil + return ctx.Err() case message := <-subscription: err = writeLog(conn, []byte(message)) if err != nil { diff --git a/experimental/libbox/command_server.go b/experimental/libbox/command_server.go index 4ca1429c..d5391cbd 100644 --- a/experimental/libbox/command_server.go +++ b/experimental/libbox/command_server.go @@ -9,6 +9,7 @@ import ( "github.com/sagernet/sing-box/log" "github.com/sagernet/sing/common" + "github.com/sagernet/sing/common/debug" E "github.com/sagernet/sing/common/exceptions" "github.com/sagernet/sing/common/observable" "github.com/sagernet/sing/common/x/list" @@ -71,7 +72,9 @@ func (s *CommandServer) loopConnection(listener net.Listener) { go func() { hErr := s.handleConnection(conn) if hErr != nil && !E.IsClosed(err) { - log.Warn("log-server: process connection: ", hErr) + if debug.Enabled { + log.Warn("log-server: process connection: ", hErr) + } } }() } diff --git a/experimental/libbox/command_status.go b/experimental/libbox/command_status.go index ac088a68..28fe5c61 100644 --- a/experimental/libbox/command_status.go +++ b/experimental/libbox/command_status.go @@ -42,7 +42,7 @@ func (s *CommandServer) handleStatusConn(conn net.Conn) error { } select { case <-ctx.Done(): - return nil + return ctx.Err() case <-ticker.C: } }