From 7095f1c6540612be7df25ece8f6f141b6089a844 Mon Sep 17 00:00:00 2001 From: Luis Pabon Date: Wed, 20 Nov 2013 16:31:46 -0500 Subject: Fix double close issue in diskfile The DiskWriter was closing the file descriptor when it finished writing but initializing it to None. Therefore, the DiskFile context manager would then try to close it also. Change-Id: I188ec814d025e28c7b89532f0502ebf1d4a20a09 Signed-off-by: Luis Pabon Reviewed-on: http://review.gluster.org/6317 Reviewed-by: Peter Portante Reviewed-by: pushpesh sharma Tested-by: pushpesh sharma --- gluster/swift/obj/diskfile.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'gluster/swift/obj/diskfile.py') diff --git a/gluster/swift/obj/diskfile.py b/gluster/swift/obj/diskfile.py index 41fe6c6..fdfabb5 100644 --- a/gluster/swift/obj/diskfile.py +++ b/gluster/swift/obj/diskfile.py @@ -297,6 +297,14 @@ class DiskWriter(object): self.last_sync = 0 self.threadpool = threadpool + def close(self): + """ + Close the file descriptor + """ + if self.fd: + do_close(self.fd) + self.fd = None + def write(self, chunk): """ Write a chunk of data into the temporary file. @@ -407,7 +415,7 @@ class DiskWriter(object): break # Close here so the calling context does not have to perform this # in a thread. - do_close(self.fd) + self.close() def put(self, metadata, extension='.data'): """ @@ -762,11 +770,7 @@ class DiskFile(SwiftDiskFile): dw = DiskWriter(self, fd, tmppath, self.threadpool) yield dw finally: - try: - if dw.fd: - do_close(dw.fd) - except OSError: - pass + dw.close() if dw.tmppath: do_unlink(dw.tmppath) -- cgit