From adcad744527d75accf778cc71dbbd5dc10039a87 Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Mon, 2 May 2022 16:47:48 +0800 Subject: [PATCH] refactor: provider init order --- adapter/provider/vehicle.go | 2 +- hub/executor/executor.go | 24 ++++++++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/adapter/provider/vehicle.go b/adapter/provider/vehicle.go index 30282d82..289ab3a0 100644 --- a/adapter/provider/vehicle.go +++ b/adapter/provider/vehicle.go @@ -73,7 +73,7 @@ func (h *HTTPVehicle) Read() ([]byte, error) { transport := &http.Transport{ // from http.DefaultTransport MaxIdleConns: 100, - IdleConnTimeout: 90 * time.Second, + IdleConnTimeout: 30 * time.Second, TLSHandshakeTimeout: 10 * time.Second, ExpectContinueTimeout: 1 * time.Second, DialContext: func(ctx context.Context, network, address string) (net.Conn, error) { diff --git a/hub/executor/executor.go b/hub/executor/executor.go index 54faccb1..2fe8d09d 100644 --- a/hub/executor/executor.go +++ b/hub/executor/executor.go @@ -203,15 +203,31 @@ func loadProvider(pv provider.Provider) { } func loadRuleProvider(ruleProviders map[string]provider.RuleProvider) { + wg := sync.WaitGroup{} for _, ruleProvider := range ruleProviders { - loadProvider(ruleProvider) + ruleProvider := ruleProvider + wg.Add(1) + go func() { + defer func() { wg.Done() }() + loadProvider(ruleProvider) + }() } + + wg.Wait() } -func loadProxyProvider(ruleProviders map[string]provider.ProxyProvider) { - for _, ruleProvider := range ruleProviders { - loadProvider(ruleProvider) +func loadProxyProvider(proxyProviders map[string]provider.ProxyProvider) { + wg := sync.WaitGroup{} + for _, proxyProvider := range proxyProviders { + proxyProvider := proxyProvider + wg.Add(1) + go func() { + defer func() { wg.Done() }() + loadProvider(proxyProvider) + }() } + + wg.Wait() } func updateTun(tun *config.Tun, dns *config.DNS) {