From 0772c2ba1bac540ba13cfe144444eb78f55639a1 Mon Sep 17 00:00:00 2001 From: Bilal Date: Fri, 22 May 2020 16:08:59 +0200 Subject: [PATCH] Add timeout on proxy connections --- config/config.go | 2 ++ structures/structures.go | 1 + workerclient/workerclient.go | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/config/config.go b/config/config.go index 6d069c2..efe302f 100644 --- a/config/config.go +++ b/config/config.go @@ -46,6 +46,7 @@ func generateClientConfigObject() { ClientConfig.ProxyListBaseURL = getString("PROXY_LIST_BASE_URL") ClientConfig.ProxyListReloadInterval = getInt("PROXY_LIST_RELOAD_INTERVAL") ClientConfig.ProxyListTimeout = getInt("PROXY_LIST_TIMEOUT") + ClientConfig.FetchTimeout = getInt("FETCH_TIMEOUT") customSOCKS5ProxyListString := getString("CUSTOM_SOCKS5_PROXY_LIST") customSOCKS5ProxyList := strings.Split(customSOCKS5ProxyListString, ",") @@ -78,6 +79,7 @@ func initClientConfigDefaultValues() { defaultClientConfigValues["CUSTOM_SOCKS5_PROXY_LIST"] = "" defaultClientConfigValues["PROXY_LIST_RELOAD_INTERVAL"] = "30" defaultClientConfigValues["PROXY_LIST_TIMEOUT"] = "10" + defaultClientConfigValues["FETCH_TIMEOUT"] = "60" } func initServerConfigDefaultValues() { diff --git a/structures/structures.go b/structures/structures.go index 3166780..10c0904 100644 --- a/structures/structures.go +++ b/structures/structures.go @@ -43,4 +43,5 @@ type ClientConfig struct { ProxyListTimeout int // In seconds ProxyListReloadInterval int // In minutes CustomSOCKS5ProxyList []ProxyServer + FetchTimeout int // In seconds } diff --git a/workerclient/workerclient.go b/workerclient/workerclient.go index 5b65947..d041b18 100644 --- a/workerclient/workerclient.go +++ b/workerclient/workerclient.go @@ -170,7 +170,10 @@ func fetchPage(url string, connectionId int) (string, error) { func getHttpClient(connectionId int) (*http.Client, error) { // setup a http client httpTransport := &http.Transport{} - httpClient := &http.Client{Transport: httpTransport} + httpClient := &http.Client{ + Transport: httpTransport, + Timeout: time.Duration(c.ClientConfig.FetchTimeout) * time.Second, + } if len(proxyList) == 0 { log.Printf("(%d) [PROXY] No proxy found, will continue without proxy!\n", connectionId)