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

pip crashes when loading from cache (sometimes?) #2481

Closed
alex opened this Issue Mar 5, 2015 · 10 comments

Comments

Projects
None yet
4 participants
@alex
Member

alex commented Mar 5, 2015

Traceback (most recent call last):
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/basecommand.py", line 215, in main
      status = self.run(options, args)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/commands/install.py", line 339, in run
      requirement_set.prepare_files(finder)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/req/req_set.py", line 333, in prepare_files
      upgrade=self.upgrade,
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/index.py", line 305, in find_requirement
      page = self._get_page(main_index_url, req)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/index.py", line 795, in _get_page
      return HTMLPage.get_page(link, req, session=self.session)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/index.py", line 884, in get_page
      "Cache-Control": "max-age=600",
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/requests/sessions.py", line 473, in get
      return self.request('GET', url, **kwargs)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/download.py", line 332, in request
      return super(PipSession, self).request(method, url, *args, **kwargs)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/requests/sessions.py", line 461, in request
      resp = self.send(prep, **send_kwargs)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/requests/sessions.py", line 573, in send
      r = adapter.send(request, **kwargs)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/cachecontrol/adapter.py", line 36, in send
      cached_response = self.controller.cached_request(request)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/cachecontrol/controller.py", line 100, in cached_request
      resp = self.serializer.loads(request, self.cache.get(cache_url))
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/cachecontrol/serialize.py", line 62, in loads
      return getattr(self, "_loads_v{0}".format(ver))(request, data)
    File "/home/jenkins/workspace/cryptography-pr-experimental/TOXENV/py34/label/debian8/cryptography/.tox/py34/lib/python3.4/site-packages/pip/_vendor/cachecontrol/serialize.py", line 91, in _loads_v1
      body = io.BytesIO(cached["response"].pop("body"))
  TypeError: 'str' does not support the buffer interface
@dstufft

This comment has been minimized.

Show comment
Hide comment
@dstufft

dstufft Mar 5, 2015

Member

I'm pretty sure this is caused by the older cache format using pickle. If you serialize a bytes in Python 2.x I believe it unserializes as a str in Python 3.x, or something like that. This causes things to go boom.

A work around is to ensure you're upgraded to the latest pip everywhere and blow away your cache which will get rid of the old cached items. A better fix is to get CacheControl to either treat a TypeError here as a cache miss (which would cause it to rewrite the cache in the new format) or to handle encoding/decoding as required.

Member

dstufft commented Mar 5, 2015

I'm pretty sure this is caused by the older cache format using pickle. If you serialize a bytes in Python 2.x I believe it unserializes as a str in Python 3.x, or something like that. This causes things to go boom.

A work around is to ensure you're upgraded to the latest pip everywhere and blow away your cache which will get rid of the old cached items. A better fix is to get CacheControl to either treat a TypeError here as a cache miss (which would cause it to rewrite the cache in the new format) or to handle encoding/decoding as required.

@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 7, 2015

Contributor

I'm pretty sure this is caused by the older cache format using pickle.

Some might say that "pickles are for delis". 😄

Contributor

msabramo commented Mar 7, 2015

I'm pretty sure this is caused by the older cache format using pickle.

Some might say that "pickles are for delis". 😄

@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 7, 2015

Contributor

Hmm this pickle thing may very well have been the cause of the transient problem I had in #2489

Contributor

msabramo commented Mar 7, 2015

Hmm this pickle thing may very well have been the cause of the transient problem I had in #2489

@jscn

This comment has been minimized.

Show comment
Hide comment
@jscn

jscn Mar 10, 2015

For the record, using the --no-cache-dir flag gets around this issue without having to blow away the cache. (Although of course you'll have to download all your packages each time.)

jscn commented Mar 10, 2015

For the record, using the --no-cache-dir flag gets around this issue without having to blow away the cache. (Although of course you'll have to download all your packages each time.)

@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 14, 2015

Contributor

Here's another one:

$ .tox/py27/bin/pip install pdb
Collecting pdb
  Using cached pdb-0.1.tar.gz
Collecting python-gnupg (from pdb)
  Using cached python-gnupg-0.3.7.tar.gz
Collecting argparse (from pdb)
  Exception:
  Traceback (most recent call last):
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
      requirement_set.prepare_files(finder)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/req/req_set.py", line 346, in prepare_files
      do_download, session=self.session,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 786, in unpack_url
      session,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 671, in unpack_http_url
      from_path, content_type = _download_http_url(link, session, temp_dir)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 818, in _download_http_url
      stream=True,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 473, in get
      return self.request('GET', url, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 365, in request
      return super(PipSession, self).request(method, url, *args, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 461, in request
      resp = self.send(prep, **send_kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 573, in send
      r = adapter.send(request, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 36, in send
      cached_response = self.controller.cached_request(request)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.py", line 110, in cached_request
      parsedate_tz(headers['date'])
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/structures.py", line 54, in __getitem__
      return self._store[key.lower()][1]
  KeyError: 'date'

If I remember to later, I will try to come up with a PR to prevent this from happening.

Contributor

msabramo commented Mar 14, 2015

Here's another one:

$ .tox/py27/bin/pip install pdb
Collecting pdb
  Using cached pdb-0.1.tar.gz
Collecting python-gnupg (from pdb)
  Using cached python-gnupg-0.3.7.tar.gz
Collecting argparse (from pdb)
  Exception:
  Traceback (most recent call last):
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/basecommand.py", line 232, in main
      status = self.run(options, args)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/commands/install.py", line 342, in run
      requirement_set.prepare_files(finder)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/req/req_set.py", line 346, in prepare_files
      do_download, session=self.session,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 786, in unpack_url
      session,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 671, in unpack_http_url
      from_path, content_type = _download_http_url(link, session, temp_dir)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 818, in _download_http_url
      stream=True,
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 473, in get
      return self.request('GET', url, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 365, in request
      return super(PipSession, self).request(method, url, *args, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 461, in request
      resp = self.send(prep, **send_kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 573, in send
      r = adapter.send(request, **kwargs)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 36, in send
      cached_response = self.controller.cached_request(request)
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.py", line 110, in cached_request
      parsedate_tz(headers['date'])
    File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/structures.py", line 54, in __getitem__
      return self._store[key.lower()][1]
  KeyError: 'date'

If I remember to later, I will try to come up with a PR to prevent this from happening.

@alex

This comment has been minimized.

Show comment
Hide comment
@alex

alex Mar 14, 2015

Member

FWIW, I suspect at least some of these bugs need to be sent to cachecontrol

Member

alex commented Mar 14, 2015

FWIW, I suspect at least some of these bugs need to be sent to cachecontrol

@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 14, 2015

Contributor

Yeah, quite possibly some of this could be cachecontrol issues. If so and I find some time, I will send PRs to them, if warranted.

Contributor

msabramo commented Mar 14, 2015

Yeah, quite possibly some of this could be cachecontrol issues. If so and I find some time, I will send PRs to them, if warranted.

@dstufft

This comment has been minimized.

Show comment
Hide comment
@dstufft

dstufft Mar 14, 2015

Member

Yea, this is almost certainly a cachecontrol issue.

Member

dstufft commented Mar 14, 2015

Yea, this is almost certainly a cachecontrol issue.

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Fix KeyError if cached response has no date header
This fixes errors like the following, which can happen if the cached
response has no `Date` header:

    $ pip install pdb
    Collecting pdb
      Using cached pdb-0.1.tar.gz
    Collecting python-gnupg (from pdb)
      Using cached python-gnupg-0.3.7.tar.gz
    Collecting argparse (from pdb)
      Exception:
      Traceback (most recent call last):
        ...
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 859, in _download_http_url
          stream=True,
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 476, in get
          return self.request('GET', url, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 367, in request
          return super(PipSession, self).request(method, url, *args, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 464, in request
          resp = self.send(prep, **send_kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 576, in send
          r = adapter.send(request, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 36, in send
          cached_response = self.controller.cached_request(request)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.py", line 110, in cached_request
          parsedate_tz(headers['date'])
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/structures.py", line 54, in __getitem__
          return self._store[key.lower()][1]
      KeyError: 'date'

Discovered with pypa/pip#2481

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Fix KeyError if cached response has no date header
This fixes errors like the following, which can happen if the cached
response has no `Date` header:

    $ pip install pdb
    Collecting pdb
      Using cached pdb-0.1.tar.gz
    Collecting python-gnupg (from pdb)
      Using cached python-gnupg-0.3.7.tar.gz
    Collecting argparse (from pdb)
      Exception:
      Traceback (most recent call last):
        ...
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 859, in _download_http_url
          stream=True,
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 476, in get
          return self.request('GET', url, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/download.py", line 367, in request
          return super(PipSession, self).request(method, url, *args, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 464, in request
          resp = self.send(prep, **send_kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 576, in send
          r = adapter.send(request, **kwargs)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 36, in send
          cached_response = self.controller.cached_request(request)
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/cachecontrol/controller.py", line 110, in cached_request
          parsedate_tz(headers['date'])
        File "/Users/marca/dev/git-repos/pip/.tox/py27/lib/python2.7/site-packages/pip/_vendor/requests/structures.py", line 54, in __getitem__
          return self._store[key.lower()][1]
      KeyError: 'date'

Discovered with pypa/pip#2481
@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 16, 2015

Contributor

ionrock/cachecontrol#67 should fix the issue in #2481 (comment); @alex's original problem (#2481 (comment)) is another cachecontrol issue which I'll take a look at now.

Contributor

msabramo commented Mar 16, 2015

ionrock/cachecontrol#67 should fix the issue in #2481 (comment); @alex's original problem (#2481 (comment)) is another cachecontrol issue which I'll take a look at now.

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Handle unserialize error when reading cache
e.g.: ` TypeError: 'str' does not support the buffer interface` could happen if
cache populated with one version of pickle and read by another version of
pickle

For an example, see pypa/pip#2481 (comment)
@msabramo

This comment has been minimized.

Show comment
Hide comment
@msabramo

msabramo Mar 16, 2015

Contributor

ionrock/cachecontrol#69 should fix @alex's original problem (#2481 (comment))

Contributor

msabramo commented Mar 16, 2015

ionrock/cachecontrol#69 should fix @alex's original problem (#2481 (comment))

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Add test_read_version_two_TypeError
A failing test that shows a bug:

i.e.: `TypeError: 'str' does not support the buffer interface` will be
raised if cache populated with str (byte string) using Python 2 pickle
and read back out by Python 3 version of pickle, because Python 3 will
return a str (Unicode string).

For an example, see pypa/pip#2481 (comment)

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Add test_read_v1_serialized_with_py2_TypeError
A failing test that shows a bug:

i.e.: `TypeError: 'str' does not support the buffer interface` will be
raised if cache populated with str (byte string) using Python 2 pickle
and read back out by Python 3 version of pickle, because Python 3 will
return a str (Unicode string).

For an example, see pypa/pip#2481 (comment)

msabramo added a commit to msabramo/cachecontrol that referenced this issue Mar 16, 2015

Fix test_read_v1_serialized_with_py2_TypeError
Fixes failing test that shows a bug:

i.e.: `TypeError: 'str' does not support the buffer interface` will be
raised if cache populated with str (byte string) using Python 2 pickle
and read back out by Python 3 version of pickle, because Python 3 will
return a str (Unicode string).

For an example, see pypa/pip#2481 (comment)

msabramo added a commit to msabramo/pip that referenced this issue Mar 21, 2015

msabramo added a commit to msabramo/pip that referenced this issue Mar 21, 2015

msabramo added a commit to msabramo/pip that referenced this issue Mar 22, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment