I am using flask application which is deployed on AWS EC2 and using mod_wsgi version 4.9.0 installled via pip.
Pyton version is 3.7.9.
I have daemon processes per flask instances and it is having no issues however for random apis that too not very frequent it is getting internal server error. After debugging it in deeper, found out that I can see errors Truncated or oversized response headers received from daemon process for such apis. Though these api after rerunning are working fine.
I checked where I am using any binary version of the python library like psycog-binary but we are not using it.
We are also using WSGIApplicationGroup %{GLOBAL}
<Directory /var/www/app/{app_name}/{instance_name}/service>
WSGIProcessGroup appname{app_name}{instance_name}
WSGIApplicationGroup %{GLOBAL}
WSGIScriptReloading On
Order deny,allow
Allow from all
AllowOverride All
Header always append X-Frame-Options SAMEORIGIN
Header add Content-Security-Policy "frame-ancestors 'self'"
Header add Cache-Control "no-cache, no-store"
Header set X-XSS-Protection "1; mode=block"
Header set X-Content-Type-Options nosniff
</Directory>
We are having
WSGIDaemonProcess appname{app_name}{instance_name} user=ec2-user {processes} {threads} python-home=/var/venv/myproduct/{folder_name} {request_timeout}
where processes is null and threads are 5 and request timeout is 60
Please check the requirement.txt file:
Packagenanme @ file:///app/buildagent/work/67989a9dc0f7048b/XYZ/scripts/Packagename-1.0.0.tar.gz
asn1crypto==1.5.1
attrs==23.2.0
awscli==1.29.82
azure-core==1.30.1
azure-storage-blob==12.15.0
Babel==2.11.0
backports-abc==0.5
backports.ssl-match-hostname==3.5.0.1
bcrypt==4.0.0
beautifulsoup4==4.7.1
boto3==1.28.77
botocore==1.31.82
bytecode==0.13.0
cattrs==22.2.0
Cerberus==1.3.4
certifi==2023.7.22
cffi==1.14.3
chardet==3.0.4
charset-normalizer==3.3.2
click==8.1.3
colorama==0.4.3
configparser==4.0.2
cramjam==2.8.3
croniter==1.3.15
cryptography==36.0.0
DbManager==1.0.3
ddsketch==2.0.4
ddtrace==1.7.3
Deprecated==1.2.14
dictdiffer==0.9.0
docutils==0.15.2
enum34==1.1.6
envier==0.4.0
et-xmlfile==1.0.1
exceptiongroup==1.2.1
Fabric==1.13.2
fastparquet==0.7.1
filelock==3.12.2
Flask==1.0.2
Flask-Cors==3.0.10
flask-talisman==0.7.0
Flask-WTF==1.0.1
FormsValidator @ file:///app/buildagent/work/67989a9dc0f7048b/XYZ/scripts/FormsValidator-1.0.1.tar.gz
fsspec==2023.1.0
future==0.18.3
google==2.0.2
help-center==1.0
html5lib==1.1
IDMAuthorizer==7.0.0
idna==2.7
importlib-metadata==6.7.0
iniparse==0.4
invoke==1.3.0
ipaddress==1.0.22
isodate==0.6.1
itsdangerous==1.1.0
JayDeBeApi==1.1.1
jdcal==1.4.1
Jinja2==3.0.3
jmespath==0.10.0
JPype1==0.6.3
json-table-schema==0.2.1
jsonmerge==1.8.0
jsonpatch==1.2
jsonpointer==1.9
jsonschema==2.5.1
jwcrypto==1.4
llvmlite==0.31.0
lml==0.1.0
lockfile==0.9.1
logstash-formatter==0.5.16
lxml==4.9.2
MarkupSafe==2.1.1
messytables==0.15.2
mysql-connector-python==8.0.28
Naked==0.1.31
nose==1.3.7
numba==0.49.0
numpy==1.20.3
oauthlib==2.0.1
openpyxl==3.0.0
oscrypto==1.3.0
packaging==24.0
pandas==1.3.5
paramiko==2.10.1
pbr==5.4.4
pkg_resources==0.0.0
ply==3.4
protobuf==4.21.12
psutil==5.7.0
psycopg2==2.7.5
pyarrow==8.0.0
pyasn1==0.4.8
pycparser==2.18
pycryptodome==3.17
pycryptodomex==3.20.0
pyexcel==0.5.12
pyexcel-io==0.6.4
pyexcel-xls==0.5.8
PyExcelerate==0.10.0
PyHive==0.6.1
PyJWT==2.6.0
PyNaCl==1.4.0
pyOpenSSL==22.0.0
pytest-runner==6.0.0
python-dateutil==2.8.1
python-logstash==0.4.6
python-magic==0.4.18
python-snappy==0.5.4
pytz==2022.7.1
PyYAML==5.4
repoze.lru==0.4
requests==2.31.0
RevoLogger==1.0.4
rsa==4.7
s3transfer==0.7.0
Salesforce-FuelSDK==1.3.0
sasl==0.3.1
shellescape==3.4.1
simple-salesforce==0.74.3
simplejson==3.2.0
singledispatch==3.4.0.3
six==1.15.0
snowflake-connector-python==3.0.4
sortedcontainers==2.4.0
soupsieve==2.4.1
sqlparse==0.2.4
stevedore==1.31.0
suds==1.1.2
suds-jurko==0.6
tenacity==8.2.3
texttable==1.6.3
thrift==0.13.0
thrift-sasl==0.3.0
typing_extensions==4.7.1
urllib3==1.26.14
webencodings==0.5.1
Werkzeug==1.0.1
wrapt==1.16.0
WTForms==2.3.3
xlrd==1.2.0
XlsxWriter==1.1.8
xlwt==1.3.0
xmltodict==0.13.0
zipp==3.15.0
I have checked few things around the error and founs out wsgi_scan_headers method in the mod_wsgi packages where this error was getting generated. I think Set-Cookie and WWW-Authenticate should get overlapped and there I started checking how we are creating responses in our application.
def create_flat_response(self, user_detail=None, should_set_csrf_cookie=False, encode=False):
from flask import make_response
compressed_payload_length = None
if encode:
compressed_payload = gzip.compress(json_serialize_object(self.payload).encode('utf8'),self.response_compression_level)
temp_response = make_response(compressed_payload)
compressed_payload_length = len(compressed_payload)
else:
temp_response = make_response(json_serialize_object(self.payload))
if should_set_csrf_cookie:
from flask_wtf.csrf import generate_csrf
csrf_token = generate_csrf()
self.payload[ApiResponseHeaderConstants.XsrfConstants.XSRF_TOKEN] = csrf_token
if not encode:
temp_response = make_response(json_serialize_object(self.payload))
temp_response.set_cookie(
ApiResponseHeaderConstants.XsrfConstants.XSRF_TOKEN, csrf_token, secure=True, httponly=True)
response = temp_response
response = self.set_response_headers(response, encode, compressed_payload_length)
self.set_cookies(user_detail=user_detail, response=response)
return response
In set_cookies we are just setting content length and encoding type in case of encode True.
Is there any issue in this too as we are compressing main payload and then setting cooked and response headers?
I am using flask application which is deployed on AWS EC2 and using mod_wsgi version 4.9.0 installled via pip.
Pyton version is 3.7.9.
I have daemon processes per flask instances and it is having no issues however for random apis that too not very frequent it is getting internal server error. After debugging it in deeper, found out that I can see errors Truncated or oversized response headers received from daemon process for such apis. Though these api after rerunning are working fine.
I checked where I am using any binary version of the python library like psycog-binary but we are not using it.
We are also using WSGIApplicationGroup %{GLOBAL}
We are having
WSGIDaemonProcess appname{app_name}{instance_name} user=ec2-user {processes} {threads} python-home=/var/venv/myproduct/{folder_name} {request_timeout}where processes is null and threads are 5 and request timeout is 60
Please check the requirement.txt file:
I have checked few things around the error and founs out wsgi_scan_headers method in the mod_wsgi packages where this error was getting generated. I think Set-Cookie and WWW-Authenticate should get overlapped and there I started checking how we are creating responses in our application.
In set_cookies we are just setting content length and encoding type in case of encode True.
Is there any issue in this too as we are compressing main payload and then setting cooked and response headers?