forked from Mirrors/gomuks
hicli: lower http header timeout after first sync
This commit is contained in:
parent
cc4eb16c7c
commit
5189f86f81
3 changed files with 15 additions and 4 deletions
|
@ -226,6 +226,10 @@ func (gmx *Gomuks) DownloadMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
|
|
||||||
resp, err := gmx.Client.Client.Download(ctx, mxc)
|
resp, err := gmx.Client.Client.Download(ctx, mxc)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if ctx.Err() != nil {
|
||||||
|
w.WriteHeader(499)
|
||||||
|
return
|
||||||
|
}
|
||||||
log.Err(err).Msg("Failed to download media")
|
log.Err(err).Msg("Failed to download media")
|
||||||
var httpErr mautrix.HTTPError
|
var httpErr mautrix.HTTPError
|
||||||
if cacheEntry == nil {
|
if cacheEntry == nil {
|
||||||
|
@ -236,6 +240,7 @@ func (gmx *Gomuks) DownloadMedia(w http.ResponseWriter, r *http.Request) {
|
||||||
if cacheEntry.Error == nil {
|
if cacheEntry.Error == nil {
|
||||||
cacheEntry.Error = &database.MediaError{
|
cacheEntry.Error = &database.MediaError{
|
||||||
ReceivedAt: jsontime.UnixMilliNow(),
|
ReceivedAt: jsontime.UnixMilliNow(),
|
||||||
|
Attempts: 1,
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
cacheEntry.Error.Attempts++
|
cacheEntry.Error.Attempts++
|
||||||
|
|
|
@ -94,11 +94,12 @@ func New(rawDB, cryptoDB *dbutil.Database, log zerolog.Logger, pickleKey []byte,
|
||||||
Transport: &http.Transport{
|
Transport: &http.Transport{
|
||||||
DialContext: (&net.Dialer{Timeout: 10 * time.Second}).DialContext,
|
DialContext: (&net.Dialer{Timeout: 10 * time.Second}).DialContext,
|
||||||
TLSHandshakeTimeout: 10 * time.Second,
|
TLSHandshakeTimeout: 10 * time.Second,
|
||||||
// This needs to be relatively high to allow initial syncs
|
// This needs to be relatively high to allow initial syncs,
|
||||||
ResponseHeaderTimeout: 180 * time.Second,
|
// it's lowered after the first sync in postProcessSyncResponse
|
||||||
|
ResponseHeaderTimeout: 300 * time.Second,
|
||||||
ForceAttemptHTTP2: true,
|
ForceAttemptHTTP2: true,
|
||||||
},
|
},
|
||||||
Timeout: 180 * time.Second,
|
Timeout: 300 * time.Second,
|
||||||
},
|
},
|
||||||
Syncer: (*hiSyncer)(c),
|
Syncer: (*hiSyncer)(c),
|
||||||
Store: (*hiStore)(c),
|
Store: (*hiStore)(c),
|
||||||
|
|
|
@ -10,6 +10,7 @@ import (
|
||||||
"context"
|
"context"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"net/http"
|
||||||
"slices"
|
"slices"
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
@ -70,7 +71,11 @@ func (h *HiClient) postProcessSyncResponse(ctx context.Context, resp *mautrix.Re
|
||||||
if syncCtx.shouldWakeupRequestQueue {
|
if syncCtx.shouldWakeupRequestQueue {
|
||||||
h.WakeupRequestQueue()
|
h.WakeupRequestQueue()
|
||||||
}
|
}
|
||||||
h.firstSyncReceived = true
|
if !h.firstSyncReceived {
|
||||||
|
h.firstSyncReceived = true
|
||||||
|
h.Client.Client.Transport.(*http.Transport).ResponseHeaderTimeout = 60 * time.Second
|
||||||
|
h.Client.Client.Timeout = 180 * time.Second
|
||||||
|
}
|
||||||
if !syncCtx.evt.IsEmpty() {
|
if !syncCtx.evt.IsEmpty() {
|
||||||
h.EventHandler(syncCtx.evt)
|
h.EventHandler(syncCtx.evt)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue