Hi we are facing an issue with python flask running on Kubernetes(EKS), we never faced this issue while running the same app on EC2 servers
The issue is while reading the incoming request payload. it is not reproducible and it happens once in 100 requests, sometimes it takes time ~1 to 5 sec, some times it is throwing an error at the 20s, mentioned the error below
builtins:OSError
cannot read from timed out object
Below is the code we are using
from werkzeug.datastructures import ImmutableMultiDict
def request_parser():
'''
Request Parser will parse args and kwargs from request object
where args are ImmutableMultiDict, convert to_dict with flat=False,
and return only dict type
'''
try:
if request.method == "GET":
args = request.args
elif request.method in ("POST", "PUT"):
args = request.json or request.form
elif request.method == "DELETE":
args = request.args
if request.get_json(silent=True):
request.json.update(request.args.to_dict(flat=False))
args = request.json
else:
args = request.args
# Checking if the args is immutablemultidict
# if it then it is required to change to dict
# because of change in python3.
if isinstance(args, ImmutableMultiDict):
args = args.to_dict(flat=False)
return args
except Exception as e:
return {}```
from the tracing, we noticed that all the requests that are taking time are being stuck at the line `args = request.json or request.form` , sometimes it takes more time, some times(very rarely) it times out with the above-mentioned exception in flask Kubernetes environment, if anyone has faced a similar issue please share your inputs
Any sort of inputs will be helpful
### Cluster information:
Kubernetes version: 1.23
Cloud being used: EKS (AWS)
Installation method:
Host OS: Linux AWS
CNI and version: latest
CRI and version: latest