78 Commits

Author SHA1 Message Date
Pawel Stolowski
c8122fc15a store: set ResponseHeaderTimeout on the default transport
It appears that ResponseHeaderTimeout needs to be set explicitly, no headers response from the server doesn't seem to be covered by any other timeout.

This should fix the download getting stuck issue.

For more context, see the stacktrace obtained from a system where download got stuck: https://pastebin.canonical.com/p/nZkRMTBbv3/
(the affected goroutine seems to be sitting inside for-select loop of /usr/lib/go-1.10/src/net/http/transport.go:2033)

(to play with it comment out ResponseHeaderTimeout: ... from transport.go and modify test timeout from 5 * time.Second to a huge value and it should be stuck)

* Set ResponseHeaderTimeout on the default transport.

* Use 250ms for mocked ResponseHeaderTimeout.

* Bump ResponseHeaderTimeout to 15s.

* Bump test timeout to avoid potential issues with LP builds.
2021-07-13 11:21:01 +02:00
Samuele Pedroni
610b870bef many: drive-py: fix spelling of PersistentNetworkError 2020-05-25 16:59:55 +02:00
Maciej Borzecki
2c3460bfbc httputil: fix client timeout retry tests
The detection of timeout coupled with context.DeadlineExceeded errors in
http.Client.do() is racy, and boils down to `time.Now().After(deadline)` where
deadline is based on the timeout setting of the client.

This has been partially fixed in 1.14 in
7fc2625ef1 but
feels more reliable if returned via err when reading the response body.

Make the tests expect either the proper `Client.Timeout exceeded while awaiting
headers` or context deadline exceeded error.

Signed-off-by: Maciej Borzecki <maciej.zenon.borzecki@canonical.com>
2020-04-15 11:53:09 +02:00
Jamie Strandboge
0c61060113 fix comment string in last commit 2020-04-07 21:52:53 +00:00
Jamie Strandboge
40dab754a3 httputil/client_test.go: account for go-1.6 error string 2020-04-07 21:41:59 +00:00
Jamie Strandboge
831af9cbb0 Merge remote-tracking branch 'refs/remotes/upstream/master' into add-more-httputil-unittests 2020-04-07 21:34:40 +00:00
Michael Vogt
0dec741e85 httputil: increase testRetryStrategy max timelimit to 5s
On the (very slow) armhf builder one unit test failed with:
```
FAIL: retry_test.go:359: retrySuite.TestRetryRequestTimeoutHandling

retry_test.go:411:
    // check that we exhausted all retries (as defined by mocked retry strategy)
    c.Assert(permanentlyBrokenSrvCalls.Count(), Equals, 5)
... obtained int = 4
... expected int = 5
```
This is caused by the retry stragey limit of 1s. The timeout of
the retry to increased to 100ms recently and it looks like this
can sometimes cause the test to go over the 1s retry strategy
limit now. This commit increases this timeout to make this much
less likely.
2020-04-03 17:14:40 +02:00
Michael Vogt
cb2243bcb8 httputil: increase httpclient timeout in TestRetryRequestTimeoutHandling
The test uses a short 25ms connect timeout. Slow (overcommitted)
systems may fail because they are unable to reply in this time.

This commit changes the timeout to 100ms which makes it at least
4x less likely to hit this condition. It also makes the test
slower unfortunately (by ~400ms).
2020-04-03 08:29:42 +02:00
Michael Vogt
70304c3433 travis.yml: run unit tests with go/master as well
* travis.yml: run unit tests with go/master as well

The unit tests of snapd are broken currently for golang-1.14. This
was observed on debian-sid. We did not catch this. To ensure we
get an early warning about failures with the latest go this PR
adds "master" to the go versions to run the unit tests against.

This commit also fixes the broken tests with 1.14
2020-03-19 09:28:01 +01:00
Jamie Strandboge
e3769c2764 httputil/client_test.go: add two TLS version tests 2020-03-18 21:04:12 +00:00
Samuele Pedroni
c30b43760c many: introduce snapdenv and snapdenv.Testing
introduce a new package snapdenv to present the common env options
for snapd components

start with snadpenv.Testing exposing SNAPPY_TESTING

it doesn't make sense for *util packages to use snapdenv directly,
as a consequence move (Set)UserAgent from httputil to snapdenv
2020-03-15 16:40:25 +01:00
Michael Vogt
6d7e4d2bd0 httputils: simplify addLocalSSLCertificates (thanks for zyga) 2020-03-11 10:50:24 +01:00
Michael Vogt
dd0c1dfeb1 many: rename dirs.SnapdExtraSSLCertsDir -> dirs.SnapdStoreSSLCertsDir 2020-03-11 09:21:06 +01:00
Michael Vogt
c7bd3a732a httputil: tweak client error messages (thanks to Samuele) 2020-03-10 17:39:38 +01:00
Michael Vogt
0e37450a3f httputil: fix vet errors in tests 2020-03-10 12:42:52 +01:00
Michael Vogt
24cce83de6 httputil: fix typo (thanks to Maciej) 2020-03-10 12:42:42 +01:00
Michael Vogt
3d1af04e44 httputil: simplify code 2020-03-06 19:40:39 +01:00
Michael Vogt
bda54d356b httputil: add a bunch of docstrings 2020-03-06 19:33:02 +01:00
Michael Vogt
611fe9b8b8 httputil: ensure both with no options and with an empty certs dir self-signed certs are not enough 2020-03-06 19:25:19 +01:00
Michael Vogt
8262a065f8 httputil: ensure minimal tls version is 1.2 2020-03-06 19:17:06 +01:00
Michael Vogt
77c64cc95f snap-repair, store: use httputil.ExtraSSLCertsFromDir where needed 2020-03-06 18:59:35 +01:00
Michael Vogt
8f4c661091 httputil: add ExtraSSLCerts abstraction 2020-03-06 18:03:18 +01:00
Michael Vogt
34eb5ca55c httputils: tweak log message when store certs cannot be added 2020-02-21 17:38:18 +01:00
Michael Vogt
c157b49354 httputils: clarify comments 2020-02-21 17:38:11 +01:00
Michael Vogt
ab468c2dc5 httputill: rename Ssl -> SSL 2020-02-21 16:54:23 +01:00