changeset 44139:2ad4e8aefcf4

lfs: explicitly close the file handle for the blob being uploaded The previous code relied on reading the blob fully to close it. The obvious problem is if an error occurs before that point. But there is also a problem when using workers where the data may need to be re-read, which can't happen once it is closed. This eliminates the surprising behavior before attempting to fix the worker problem. Differential Revision: https://phab.mercurial-scm.org/D7957
author Matt Harbison <matt_harbison@yahoo.com>
date Tue, 21 Jan 2020 09:51:39 -0500
parents 5f841daf3b41
children b2408acaa4c9
files hgext/lfs/blobstore.py
diffstat 1 files changed, 7 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/lfs/blobstore.py	Tue Jan 21 09:40:40 2020 -0500
+++ b/hgext/lfs/blobstore.py	Tue Jan 21 09:51:39 2020 -0500
@@ -110,11 +110,12 @@
     def read(self, size):
         if self._fp is None:
             return b''
-        data = self._fp.read(size)
-        if not data:
+        return self._fp.read(size)
+
+    def close(self):
+        if self._fp is not None:
             self._fp.close()
             self._fp = None
-        return data
 
 
 class local(object):
@@ -539,6 +540,9 @@
             raise LfsRemoteError(
                 _(b'LFS error: %s') % _urlerrorreason(ex), hint=hint
             )
+        finally:
+            if request.data:
+                request.data.close()
 
     def _batch(self, pointers, localstore, action):
         if action not in [b'upload', b'download']: