Symptoms


When checking order on order-managent Rest API using python as client, the request sometimes failed with Remote end closed connection without response.


For example:

2023-05-25 21:12:25,710 - __main__.utilities.order - DEBUG - Result {'orderId': 'XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB',
'paymentCreationResult': {'paymentId': 1000001}}
2023-05-25 21:12:27,879 - __main__.utilities.order - INFO - Order XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB Status NOT_STARTED
2023-05-25 21:12:27,879 - __main__.utilities.order - INFO - Waiting for Order to start
2023-05-25 21:12:33,037 - __main__.utilities.order - INFO - Order XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB Status NOT_STARTED
2023-05-25 21:12:33,042 - __main__.utilities.order - INFO - Waiting for Order to start
2023-05-25 21:12:38,212 - __main__.utilities.order - INFO - Order XXXXXXXX-YYYY-ZZZZ-AAAA-BBBBBBBBBBBB Status NOT_STARTED
2023-05-25 21:12:38,212 - __main__.utilities.order - INFO - Waiting for Order to start
Traceback (most recent call last):
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 600, in urlopen
chunked=chunked)
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 384, in _make_request
six.raise_from(e, None)
File "", line 2, in raise_from
File "C:\Python37\lib\site-packages\urllib3\connectionpool.py", line 380, in _make_request
httplib_response = conn.getresponse()
File "C:\Python37\lib\http\client.py", line 1344, in getresponse
response.begin()
File "C:\Python37\lib\http\client.py", line 306, in begin
version, status, reason = self._read_status()
File "C:\Python37\lib\http\client.py", line 275, in _read_status
raise RemoteDisconnected("Remote end closed connection without"
http.client.RemoteDisconnected: Remote end closed connection without response


Checking branding-ui pod, oss pod and ordermanagement pod using command below, there was no error that could be seen during the latest request where it was failed with "Remote end closed connection without response":

kubectl logs branding-ui-cluster-ui-xxxxxxx-yyyyy | less
kubectl logs oss-node-0 | less
kubectl logs ordermanagement-xxxxxx-yyyyy | less


Cause


Issue with Oauth1Session implementation on default/built-in python library.

The session was not kept alive between the request.


Resolution


Use different tools (eg. Postman/Insomnia) to use the API instead of python.


If use of python is needed, then consider alternative library for session creation, httpx_client lib, for example:

from authlib.integrations.httpx_client import AsyncOAuth1Client
...
session = AsyncOAuth1Client(consumer_key, consumer_secret)

For more information refer to library documentation: https://docs.authlib.org/en/latest/client/api.html#authlib.integrations.httpx_client.AsyncOAuth1Client


Alternatively, you can also tune HttpAdapter as per the example below:

from authlib.integrations.requests_client import OAuth1Session
from requests.adapters import HTTPAdapter
...
session = OAuth1Session(consumer_key, consumer_secret, realm=url)
session.mount('https://', HTTPAdapter(max_retries=2))