From 3bf3f2305373d69d6346d38b70be8add2a53f029 Mon Sep 17 00:00:00 2001 From: Mathieu Velten Date: Tue, 27 Jun 2023 20:07:21 +0200 Subject: [PATCH] Increase timeout of init sync to 30mn for small homeservers --- sync2/client.go | 11 ++++++++++- v3.go | 2 +- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/sync2/client.go b/sync2/client.go index 7e9a8167..9a0a7b30 100644 --- a/sync2/client.go +++ b/sync2/client.go @@ -7,6 +7,7 @@ import ( "io/ioutil" "net/http" "net/url" + "time" "github.com/matrix-org/gomatrixserverlib" "github.com/tidwall/gjson" @@ -69,7 +70,15 @@ func (v *HTTPClient) DoSyncV2(ctx context.Context, accessToken, since string, is if err != nil { return nil, 0, fmt.Errorf("DoSyncV2: NewRequest failed: %w", err) } - res, err := v.Client.Do(req) + var res *http.Response + if isFirst { + longTimeoutClient := &http.Client{ + Timeout: 30 * time.Minute, + } + res, err = longTimeoutClient.Do(req) + } else { + res, err = v.Client.Do(req) + } if err != nil { return nil, 0, fmt.Errorf("DoSyncV2: request failed: %w", err) } diff --git a/v3.go b/v3.go index 74ae2be2..581eeaff 100644 --- a/v3.go +++ b/v3.go @@ -73,7 +73,7 @@ func Setup(destHomeserver, postgresURI, secret string, opts Opts) (*handler2.Han // Setup shared DB and HTTP client v2Client := &sync2.HTTPClient{ Client: &http.Client{ - Timeout: 5 * time.Minute, + Timeout: 45 * time.Second, }, DestinationServer: destHomeserver, }