Relax TCP timeouts for koji connections

See COMPOSER-1354 and linked tickets
This commit is contained in:
Diaa Sami 2022-02-09 19:37:32 +01:00 committed by Ondřej Budai
parent 631bd21ffe
commit c1ae5b0881
5 changed files with 47 additions and 45 deletions

View file

@ -2,9 +2,13 @@ package koji
import (
"bytes"
"net"
"time"
// koji uses MD5 hashes
/* #nosec G501 */
"crypto/md5"
"crypto/tls"
"encoding/json"
"errors"
"fmt"
@ -420,3 +424,24 @@ func GSSAPICredentialsFromEnv() (*GSSAPICredentials, error) {
KeyTab: keyTab,
}, nil
}
func CreateKojiTransport(relaxTimeout uint) *http.Transport {
// Koji for some reason needs TLS renegotiation enabled.
// Clone the default http transport and enable renegotiation.
transport := http.DefaultTransport.(*http.Transport).Clone()
transport.TLSClientConfig = &tls.Config{
Renegotiation: tls.RenegotiateOnceAsClient,
MinVersion: tls.VersionTLS12,
}
// Relax timeouts a bit
if relaxTimeout > 0 {
transport.TLSHandshakeTimeout *= time.Duration(relaxTimeout)
transport.DialContext = (&net.Dialer{
Timeout: 30 * time.Second * time.Duration(relaxTimeout),
KeepAlive: 30 * time.Second,
}).DialContext
}
return transport
}