-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pypi, retry when receiving a 200 with empty body #4717
pypi, retry when receiving a 200 with empty body #4717
Conversation
For some reason, pypi is returning a 200 and an empty body from time to time. The next time you query the same endpoint it returns a proper JSON object. This is not fixing a bug in poetry, but working around the issue.
8ea86ad
to
2939ca5
Compare
i'm also seeing this, its gotten to the point that poetry almost feels unusable if not unreliable. looking at the headers there's nothing in particular distinguishing the response. i dropped a pdb in to introspect the headers
(Pdb) json_response.content
b''
(Pdb) pp dict(json_response.headers)
{'Accept-Ranges': 'bytes',
'Access-Control-Allow-Headers': 'Content-Type, If-Match, If-Modified-Since, '
'If-None-Match, If-Unmodified-Since',
'Access-Control-Allow-Methods': 'GET',
'Access-Control-Allow-Origin': '*',
'Access-Control-Expose-Headers': 'X-PyPI-Last-Serial',
'Access-Control-Max-Age': '86400',
'Cache-Control': 'max-age=900, public',
'Connection': 'keep-alive',
'Content-Encoding': 'gzip',
'Content-Length': '9341',
'Content-Security-Policy': "base-uri 'self'; block-all-mixed-content; "
"connect-src 'self' https://api.github.com/repos/ "
'*.fastly-insights.com sentry.io '
'https://api.pwnedpasswords.com '
'https://2p66nmmycsj3.statuspage.io; default-src '
"'none'; font-src 'self' fonts.gstatic.com; "
"form-action 'self'; frame-ancestors 'none'; "
"frame-src 'none'; img-src 'self' "
'https://warehouse-camo.ingress.cmh1.psfhosted.org/ '
'www.google-analytics.com *.fastly-insights.com; '
"script-src 'self' www.googletagmanager.com "
'www.google-analytics.com *.fastly-insights.com '
"https://cdn.ravenjs.com; style-src 'self' "
'fonts.googleapis.com; worker-src '
'*.fastly-insights.com',
'Content-Type': 'application/json',
'Date': 'Sun, 07 Nov 2021 15:11:35 GMT',
'ETag': '"JuWbHOCwMq+jjOgbucA39g"',
'Referrer-Policy': 'origin-when-cross-origin',
'Server': 'nginx/1.13.9',
'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload',
'Vary': 'Accept-Encoding',
'X-Cache': 'HIT',
'X-Cache-Hits': '1',
'X-Content-Type-Options': 'nosniff',
'X-Frame-Options': 'deny',
'X-Permitted-Cross-Domain-Policies': 'none',
'X-PyPI-Last-Serial': '8237314',
'X-Served-By': 'cache-wdc5550-WDC',
'X-Timer': 'S1636297896.913867,VS0,VE1',
'X-XSS-Protection': '1; mode=block'}
(Pdb) json_response.__dict__.keys()
dict_keys(['_content', '_content_consumed', '_next', 'status_code', 'headers', 'raw', 'url', 'encoding', 'history', 'reason', 'cookies', 'elapsed', 'request', 'connection', 'from_cache'])
(Pdb) json_response.request
<PreparedRequest [GET]>
(Pdb) json_response.request.__dict__
{'method': 'GET', 'url': 'https://pypi.org/pypi/cached-property/json', 'headers': {'User-Agent': 'python-requests/2.26.0', 'Accept-Encoding': 'gzip, deflate', 'Accept': '*/*', 'Connection': 'keep-alive', 'If-None-Match': '"JuWbHOCwMq+jjOgbucA39g"'}, '_cookies': <RequestsCookieJar[]>, 'body': None, 'hooks': {'response': []}, '_body_position': None} using the patch in this pr does make things work... its also illustrative of how common the problem is given the number of empty body retries, and how problematic poetry is without it. as else each of those would have have been a jsondecode error.
|
Has anyone reported this upstream as well? I assume https://github.com/pypa/warehouse/issues would be the right place? |
How certain are you that PyPi is the problem? I haven't been able to replicate with |
@austinbutler haven't reported upstream (nor do i see another report against recent issues), re curl/requests, it could be a particular set of headers. |
I'm not sure/convinced this is the right approach -- like has been mentioned upthread, attempting to determine if this is to do with a bug in a Poetry dependency, or in PyPI itself, is likely more productive. @j-martin do you have any particular steps that can reproduce the empty response issue? |
@neersighted it seems to be fairly random and is definitely an issue on pypi's side. I have not encountered it lately, but one of my coworkers just hit the same issue. I have opened pypi/warehouse#10387 as suggested by @austinbutler. |
per the suggestion on pypi warehouse issue, i tried disabling the cache control and can confirm that it works without any retries. afaics cache control usage here is independent of the package cache ('artifacts' vs cache/repositories), so can safely be disabled without significant ux behavior effects. |
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
For some reason, pypi is returning a 200 and an empty body from time to time. The next time you query the same endpoint it returns a proper JSON object. This is not fixing a bug in poetry, but working around the issue.
This was resulting in issue where anything operation modifying the lock file would randomly fail due to
JSONDecodeError
. This is unrelated to #4592Pull Request Check List
Resolves: Issue not created.