From 1319f728053ea94fd43a0a3803930bbe9325aaf6 Mon Sep 17 00:00:00 2001 From: yusing Date: Fri, 30 Jan 2026 00:23:03 +0800 Subject: [PATCH] refactor: propagate context and standardize HTTP client timeouts Add context parameter to TCP/UDP stream health checks and client constructors for proper cancellation and deadline propagation. Switch from encoding/json to sonic for faster JSON unmarshaling. Standardize HTTP client timeouts to 5 seconds across agent pool and health check. --- agent/pkg/agent/config.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/agent/pkg/agent/config.go b/agent/pkg/agent/config.go index 2d18353d..404554e4 100644 --- a/agent/pkg/agent/config.go +++ b/agent/pkg/agent/config.go @@ -4,7 +4,6 @@ import ( "context" "crypto/tls" "crypto/x509" - "encoding/json" "encoding/pem" "errors" "fmt" @@ -16,6 +15,7 @@ import ( "strings" "time" + "github.com/bytedance/sonic" "github.com/rs/zerolog" "github.com/rs/zerolog/log" "github.com/yusing/godoxy/agent/pkg/agent/common" @@ -366,7 +366,7 @@ func (cfg *AgentConfig) fetchJSON(ctx context.Context, endpoint string, out any) return resp.StatusCode, nil } - err = json.Unmarshal(data, out) + err = sonic.Unmarshal(data, out) if err != nil { return 0, err }