Repository: conda/conda

Issue:
BufferError when trying to update conda
I get the following error when running the `conda update conda` command.

The error message does not seem to provide any hint of what may be wrong. Anyone has a guess of what might be the problem?

```
PS C:\> conda update conda
Fetching package metadata ...An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

    https://github.com/conda/conda/issues



Current conda install:

               platform : win-64
          conda version : 4.3.7
       conda is private : False
      conda-env version : 4.3.7
    conda-build version : 1.21.6
         python version : 3.4.0.final.0
       requests version : 2.12.4
       root environment : C:\Anaconda3  (writable)
    default environment : C:\Anaconda3
       envs directories : C:\Anaconda3\envs
          package cache : C:\Anaconda3\pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
            config file : None
           offline mode : False
             user-agent : conda/4.3.7 requests/2.12.4 CPython/3.4.0 Windows/7 Windows/6.1.7601



`$ C:\Anaconda3\Scripts\conda-script.py update conda`




    Traceback (most recent call last):
      File "C:\Anaconda3\lib\site-packages\conda\exceptions.py", line 617, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "C:\Anaconda3\lib\site-packages\conda\cli\main_update.py", line 65, in execute
        install(args, parser, 'update')
      File "C:\Anaconda3\lib\site-packages\conda\cli\install.py", line 210, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 120, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 445, in fetch_index
        repodatas = _collect_repodatas(use_cache, urls)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 433, in _collect_repodatas
        repodatas = _collect_repodatas_serial(use_cache, urls)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 401, in _collect_repodatas_serial
        for url in urls]
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 401, in <listcomp>
        for url in urls]
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 141, in func
        res = f(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 364, in fetch_repodata
        mod_etag_headers = read_mod_and_etag(cache_path)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 153, in read_mod_and_etag
        return result
      File "C:\Anaconda3\lib\contextlib.py", line 152, in __exit__
        self.thing.close()
    BufferError: cannot close exported pointers exist

PS C:\>
```
BufferError when trying to update conda
I get the following error when running the `conda update conda` command.

The error message does not seem to provide any hint of what may be wrong. Anyone has a guess of what might be the problem?

```
PS C:\> conda update conda
Fetching package metadata ...An unexpected error has occurred.
Please consider posting the following information to the
conda GitHub issue tracker at:

    https://github.com/conda/conda/issues



Current conda install:

               platform : win-64
          conda version : 4.3.7
       conda is private : False
      conda-env version : 4.3.7
    conda-build version : 1.21.6
         python version : 3.4.0.final.0
       requests version : 2.12.4
       root environment : C:\Anaconda3  (writable)
    default environment : C:\Anaconda3
       envs directories : C:\Anaconda3\envs
          package cache : C:\Anaconda3\pkgs
           channel URLs : https://repo.continuum.io/pkgs/free/win-64
                          https://repo.continuum.io/pkgs/free/noarch
                          https://repo.continuum.io/pkgs/r/win-64
                          https://repo.continuum.io/pkgs/r/noarch
                          https://repo.continuum.io/pkgs/pro/win-64
                          https://repo.continuum.io/pkgs/pro/noarch
                          https://repo.continuum.io/pkgs/msys2/win-64
                          https://repo.continuum.io/pkgs/msys2/noarch
            config file : None
           offline mode : False
             user-agent : conda/4.3.7 requests/2.12.4 CPython/3.4.0 Windows/7 Windows/6.1.7601



`$ C:\Anaconda3\Scripts\conda-script.py update conda`




    Traceback (most recent call last):
      File "C:\Anaconda3\lib\site-packages\conda\exceptions.py", line 617, in conda_exception_handler
        return_value = func(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\conda\cli\main.py", line 137, in _main
        exit_code = args.func(args, p)
      File "C:\Anaconda3\lib\site-packages\conda\cli\main_update.py", line 65, in execute
        install(args, parser, 'update')
      File "C:\Anaconda3\lib\site-packages\conda\cli\install.py", line 210, in install
        unknown=index_args['unknown'], prefix=prefix)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 120, in get_index
        index = fetch_index(channel_priority_map, use_cache=use_cache)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 445, in fetch_index
        repodatas = _collect_repodatas(use_cache, urls)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 433, in _collect_repodatas
        repodatas = _collect_repodatas_serial(use_cache, urls)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 401, in _collect_repodatas_serial
        for url in urls]
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 401, in <listcomp>
        for url in urls]
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 141, in func
        res = f(*args, **kwargs)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 364, in fetch_repodata
        mod_etag_headers = read_mod_and_etag(cache_path)
      File "C:\Anaconda3\lib\site-packages\conda\core\index.py", line 153, in read_mod_and_etag
        return result
      File "C:\Anaconda3\lib\contextlib.py", line 152, in __exit__
        self.thing.close()
    BufferError: cannot close exported pointers exist

PS C:\>
```


Discussion:
Thanks for the report.  Definitely one I haven't seen before.  Easy fix though.
Thanks for the report.  Definitely one I haven't seen before.  Easy fix though.

Resolving patch:
diff --git a/conda/core/index.py b/conda/core/index.py
--- a/conda/core/index.py
+++ b/conda/core/index.py
@@ -154,7 +154,9 @@ def read_mod_and_etag(path):
                 match_objects = take(3, re.finditer(REPODATA_HEADER_RE, m))
                 result = dict(map(ensure_unicode, mo.groups()) for mo in match_objects)
                 return result
-        except ValueError:
+        except (BufferError, ValueError):
+            # BufferError: cannot close exported pointers exist
+            #   https://github.com/conda/conda/issues/4592
             # ValueError: cannot mmap an empty file
             return {}
 


Test patch: