mirror of
https://github.com/qdm12/gluetun.git
synced 2026-06-19 09:54:09 +02:00
fix(all): increase global http client timeout to 35s and precise lower timeouts where needed
- Fix DNS blocklists slow downloads, fix #3102 - Leave 35s timeout for updaters - Set timeouts to 1s for local calls - Set timeouts to 5s for LAN VPN calls and small external calls - Set timeouts to 10s external VPN API calls
This commit is contained in:
+1
-1
@@ -264,7 +264,7 @@ func _main(ctx context.Context, buildInfo models.BuildInformation,
|
|||||||
|
|
||||||
puid, pgid := int(*allSettings.System.PUID), int(*allSettings.System.PGID)
|
puid, pgid := int(*allSettings.System.PUID), int(*allSettings.System.PGID)
|
||||||
|
|
||||||
const clientTimeout = 15 * time.Second
|
const clientTimeout = 35 * time.Second
|
||||||
httpClient := &http.Client{Timeout: clientTimeout}
|
httpClient := &http.Client{Timeout: clientTimeout}
|
||||||
// Create configurators
|
// Create configurators
|
||||||
alpineConf := alpine.New()
|
alpineConf := alpine.New()
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
var ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK")
|
var ErrHTTPStatusNotOK = errors.New("HTTP response status is not OK")
|
||||||
@@ -21,6 +22,9 @@ func NewClient(httpClient *http.Client) *Client {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *Client) Check(ctx context.Context, url string) error {
|
func (c *Client) Check(ctx context.Context, url string) error {
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, time.Second)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
|||||||
@@ -260,6 +260,12 @@ func fetchToken(ctx context.Context, client *http.Client,
|
|||||||
url.QueryEscape(password): "<password>",
|
url.QueryEscape(password): "<password>",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 10 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
form := url.Values{}
|
form := url.Values{}
|
||||||
form.Add("username", username)
|
form.Add("username", username)
|
||||||
form.Add("password", password)
|
form.Add("password", password)
|
||||||
@@ -304,6 +310,11 @@ func fetchPortForwardData(ctx context.Context, client *http.Client, apiIP netip.
|
|||||||
) {
|
) {
|
||||||
errSubstitutions := map[string]string{url.QueryEscape(token): "<token>"}
|
errSubstitutions := map[string]string{url.QueryEscape(token): "<token>"}
|
||||||
|
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
queryParams := make(url.Values)
|
queryParams := make(url.Values)
|
||||||
queryParams.Add("token", token)
|
queryParams.Add("token", token)
|
||||||
url := url.URL{
|
url := url.URL{
|
||||||
@@ -353,6 +364,12 @@ func fetchPortForwardData(ctx context.Context, client *http.Client, apiIP netip.
|
|||||||
var ErrBadResponse = errors.New("bad response received")
|
var ErrBadResponse = errors.New("bad response received")
|
||||||
|
|
||||||
func bindPort(ctx context.Context, client *http.Client, apiIPAddress netip.Addr, data piaPortForwardData) (err error) {
|
func bindPort(ctx context.Context, client *http.Client, apiIPAddress netip.Addr, data piaPortForwardData) (err error) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
payload, err := packPayload(data.Port, data.Token, data.Expiration)
|
payload, err := packPayload(data.Port, data.Token, data.Expiration)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("serializing payload: %w", err)
|
return fmt.Errorf("serializing payload: %w", err)
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/provider/common"
|
"github.com/qdm12/gluetun/internal/provider/common"
|
||||||
"github.com/qdm12/gluetun/internal/provider/utils"
|
"github.com/qdm12/gluetun/internal/provider/utils"
|
||||||
@@ -23,6 +24,12 @@ var ErrPortForwardedNotFound = errors.New("port forwarded not found")
|
|||||||
func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) (
|
func (p *Provider) PortForward(ctx context.Context, objects utils.PortForwardObjects) (
|
||||||
ports []uint16, err error,
|
ports []uint16, err error,
|
||||||
) {
|
) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 10 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
url := "https://connect.pvdatanet.com/v3/Api/port?ip[]=" + objects.InternalIP.String()
|
url := "https://connect.pvdatanet.com/v3/Api/port?ip[]=" + objects.InternalIP.String()
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"regexp"
|
"regexp"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// getMostRecentStableTag finds the most recent proton-account stable tag version,
|
// getMostRecentStableTag finds the most recent proton-account stable tag version,
|
||||||
@@ -18,6 +19,12 @@ func getMostRecentStableTag(ctx context.Context, client *http.Client) (version s
|
|||||||
page := 1
|
page := 1
|
||||||
regexVersion := regexp.MustCompile(`^proton-account@(\d+\.\d+\.\d+\.\d+)$`)
|
regexVersion := regexp.MustCompile(`^proton-account@(\d+\.\d+\.\d+\.\d+)$`)
|
||||||
for ctx.Err() == nil {
|
for ctx.Err() == nil {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
url := "https://api.github.com/repos/ProtonMail/WebClients/tags?per_page=30&page=" + fmt.Sprint(page)
|
url := "https://api.github.com/repos/ProtonMail/WebClients/tags?per_page=30&page=" + fmt.Sprint(page)
|
||||||
|
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
@@ -40,6 +41,12 @@ func (c *cloudflare) Token() (token string) {
|
|||||||
func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) (
|
func (c *cloudflare) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||||
result models.PublicIP, err error,
|
result models.PublicIP, err error,
|
||||||
) {
|
) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
urlBase := "https://speed.cloudflare.com"
|
urlBase := "https://speed.cloudflare.com"
|
||||||
url := urlBase + "/meta"
|
url := urlBase + "/meta"
|
||||||
if ip.IsValid() {
|
if ip.IsValid() {
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
)
|
)
|
||||||
@@ -44,6 +45,12 @@ func (e *echoip) Token() string {
|
|||||||
func (e *echoip) FetchInfo(ctx context.Context, ip netip.Addr) (
|
func (e *echoip) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||||
result models.PublicIP, err error,
|
result models.PublicIP, err error,
|
||||||
) {
|
) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
url := e.url + "/json"
|
url := e.url + "/json"
|
||||||
if ip.IsValid() {
|
if ip.IsValid() {
|
||||||
url += "?ip=" + ip.String()
|
url += "?ip=" + ip.String()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
@@ -44,6 +45,12 @@ func (i *ip2Location) Token() string {
|
|||||||
func (i *ip2Location) FetchInfo(ctx context.Context, ip netip.Addr) (
|
func (i *ip2Location) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||||
result models.PublicIP, err error,
|
result models.PublicIP, err error,
|
||||||
) {
|
) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
url := "https://api.ip2location.io/"
|
url := "https://api.ip2location.io/"
|
||||||
if ip.IsValid() {
|
if ip.IsValid() {
|
||||||
url += "?ip=" + ip.String()
|
url += "?ip=" + ip.String()
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import (
|
|||||||
"net/http"
|
"net/http"
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"strings"
|
"strings"
|
||||||
|
"time"
|
||||||
|
|
||||||
"github.com/qdm12/gluetun/internal/constants"
|
"github.com/qdm12/gluetun/internal/constants"
|
||||||
"github.com/qdm12/gluetun/internal/models"
|
"github.com/qdm12/gluetun/internal/models"
|
||||||
@@ -42,6 +43,12 @@ func (i *ipInfo) Token() string {
|
|||||||
func (i *ipInfo) FetchInfo(ctx context.Context, ip netip.Addr) (
|
func (i *ipInfo) FetchInfo(ctx context.Context, ip netip.Addr) (
|
||||||
result models.PublicIP, err error,
|
result models.PublicIP, err error,
|
||||||
) {
|
) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
url := "https://ipinfo.io/"
|
url := "https://ipinfo.io/"
|
||||||
switch {
|
switch {
|
||||||
case ip.Is6():
|
case ip.Is6():
|
||||||
|
|||||||
@@ -28,6 +28,12 @@ type githubCommit struct {
|
|||||||
var errHTTPStatusCode = errors.New("bad response HTTP status code")
|
var errHTTPStatusCode = errors.New("bad response HTTP status code")
|
||||||
|
|
||||||
func getGithubReleases(ctx context.Context, client *http.Client) (releases []githubRelease, err error) {
|
func getGithubReleases(ctx context.Context, client *http.Client) (releases []githubRelease, err error) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
const url = "https://api.github.com/repos/qdm12/gluetun/releases"
|
const url = "https://api.github.com/repos/qdm12/gluetun/releases"
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -53,6 +59,12 @@ func getGithubReleases(ctx context.Context, client *http.Client) (releases []git
|
|||||||
}
|
}
|
||||||
|
|
||||||
func getGithubCommits(ctx context.Context, client *http.Client) (commits []githubCommit, err error) {
|
func getGithubCommits(ctx context.Context, client *http.Client) (commits []githubCommit, err error) {
|
||||||
|
// Define a timeout since the default client has a large timeout and we don't
|
||||||
|
// want to wait too long.
|
||||||
|
const timeout = 5 * time.Second
|
||||||
|
ctx, cancel := context.WithTimeout(ctx, timeout)
|
||||||
|
defer cancel()
|
||||||
|
|
||||||
const url = "https://api.github.com/repos/qdm12/gluetun/commits"
|
const url = "https://api.github.com/repos/qdm12/gluetun/commits"
|
||||||
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
request, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user