OpenStack Storage (Swift) Client
Go to file
Kota Tsuyuzaki e65070964c Add force auth retry mode in swiftclient
This patch attemps to add an option to force get_auth call while retrying
an operation even if it gets errors other than 401 Unauthorized.

Why we need this:
The main reason why we need this is current python-swiftclient requests could
never get succeeded under certion situation using third party proxies/load balancers
between the client and swift-proxy server. I think, it would be general situation
of the use case.

Specifically describing nginx case, the nginx can close the socket from the client
when the response code from swift is not 2xx series. In default, nginx can wait the
buffers from the client for a while (default 30s)[1] but after the time past, nginx
will close the socket immediately. Unfortunately, if python-swiftclient has still been
sending the data into the socket, python-swiftclient will get socket error (EPIPE,
BrokenPipe). From the swiftclient perspective, this is absolutely not an auth error,
so current python-swiftclient will continue to retry without re-auth.
However, if the root cause is sort of 401 (i.e. nginx got 401 unauthorized from the
swift-proxy because of token expiration), swiftclient will loop 401 -> EPIPE -> 401...
until it consume the max retry times.

In particlar, less time to live of the token and multipart object upload with large
segments could not get succeeded as below:

Connection Model:

python-swiftclient -> nginx -> swift-proxy -> swift-backend

Case: Try to create slo with large segments and the auth token expired with 1 hour

1. client create a connection to nginx with successful response from swift-proxy and its auth
2. client continue to put large segment objects
   (e.g. 1~5GB for each and the total would 20~30GB, i.e. 20~30 segments)
3. after some of segments uploaded, 1 hour past but client is still trying to
   send remaining segment objects.
4. nginx got 401 from swift-proxy for a request and wait that the connection is closed
   from the client but timeout past because the python-swiftclient is still sending much data
   into the socket before reading the 401 response.
5. client got socket error because nginx closed the connection during sending the buffer.
6. client retries a new connection to nginx without re-auth...

<loop 4-6>

7. finally python-swiftclient failed with socket error (Broken Pipe)

In operational perspective, setting longer timeout for lingering close would be an option but
it's not complete solution because any other proxy/LB may not support the options.

If we actually do THE RIGHT THING in python-swiftclient, we should send expects: 100-continue
header and handle the first response to re-auth correctly.

HOWEVER, the current python's httplib and requests module used by python-swiftclient doesn't
support expects: 100-continue header [2] and the thread proposed a fix [3] is not super active.
And we know the reason we depends on the library is to fix a security issue that existed
in older python-swiftclient [4] so that we should touch around it super carefully.

In the reality, as the hot fix, this patch try to mitigate the unfortunate situation
described above WITHOUT 100-continue fix, just users can force to re-auth when any errors
occurred during the retries that can be accepted in the upstream.

1: http://nginx.org/en/docs/http/ngx_http_core_module.html#lingering_close
2: https://github.com/requests/requests/issues/713
3: https://bugs.python.org/issue1346874
4: https://review.openstack.org/#/c/69187/

Change-Id: I3470b56e3f9cf9cdb8c2fc2a94b2c551927a3440
2018-03-13 12:29:48 +09:00
bin Make bin/swift testable part 2 2014-03-25 11:36:39 +00:00
doc Update the old http doc links 2018-01-30 00:28:17 +00:00
examples Merge "Fix examples and missing code-block" 2016-08-25 20:29:54 +00:00
releasenotes Update reno for stable/queens 2018-01-29 09:21:32 -08:00
swiftclient Add force auth retry mode in swiftclient 2018-03-13 12:29:48 +09:00
tests Add force auth retry mode in swiftclient 2018-03-13 12:29:48 +09:00
.coveragerc remove swiftclient/openstack/common/* in the .coveragerc 2016-09-21 15:48:35 +08:00
.functests Fix running the unittests under py3 2014-05-09 09:29:04 +02:00
.gitignore do hand-curated authors/changelog files 2015-09-04 18:29:30 +01:00
.gitreview Add openstack project infrastructure. 2012-05-16 17:30:46 -04:00
.mailmap 3.3.0 authors/changelog update 2017-01-25 15:12:59 -08:00
.manpages adding .manpages script to swift client 2016-02-25 16:07:28 -05:00
.testr.conf Fix running the unittests under py3 2014-05-09 09:29:04 +02:00
.unittests Add functional tests for python-swiftclient 2014-05-05 11:53:37 +02:00
AUTHORS authors/changelog updates for 3.5.0 release 2018-01-24 08:36:58 +11:00
CONTRIBUTING.rst Update the old http doc links 2018-01-30 00:28:17 +00:00
ChangeLog authors/changelog updates for 3.5.0 release 2018-01-24 08:36:58 +11:00
LICENSE Add CHANGELOG LICENSE and MANIFEST.in 2012-05-08 16:30:13 +01:00
MANIFEST.in Switch to pbr for setup. 2013-05-01 12:23:12 -04:00
README.rst Update links in README 2018-03-05 13:23:54 +00:00
bindep.txt Update the old http doc links 2018-01-30 00:28:17 +00:00
requirements.txt Installs futures only for python 2.7 and 2.6 2016-09-27 16:28:11 +00:00
run_tests.sh Add run_tests.sh script here. 2012-05-21 12:52:55 +02:00
setup.cfg Update the documentation link for doc migration 2017-07-24 09:49:59 -07:00
setup.py Add python version constraint python>=2.7 2016-07-06 02:16:52 +00:00
test-requirements.txt Add releasenotes tox env 2017-08-08 22:03:59 +00:00
tox.ini Revert "Add Constraints support" 2018-01-17 11:13:59 -08:00

README.rst

Team and repository tags

image

Python bindings to the OpenStack Object Storage API

Latest Version

Downloads

This is a python client for the Swift API. There's a Python API (the swiftclient module), and a command-line script (swift).

Development takes place via the usual OpenStack processes as outlined in the OpenStack wiki.

This code is based on the original client previously included with OpenStack's Swift The python-swiftclient is licensed under the Apache License like the rest of OpenStack.

Contents: