← Back to team overview

dulwich-users team mailing list archive

[PATCH] Race condition in DiskObjectStore.add_object

 

Hi,

We are using dulwich in a project. It is good!

Our daemon is threaded and we have managed to hit a race condition while
creating objects. I believe the attached patch fixes this. Please can
you apply it?

Bruce

In threaded programs, more than one thread can try to add the same object at
the same time and this can cause os.mkdir to fail.
---
 dulwich/object_store.py |    5 ++++-
 1 files changed, 4 insertions(+), 1 deletions(-)

diff --git a/dulwich/object_store.py b/dulwich/object_store.py
index ca26348..46832f5 100644
--- a/dulwich/object_store.py
+++ b/dulwich/object_store.py
@@ -470,8 +470,11 @@ class DiskObjectStore(PackBasedObjectStore):
         :param obj: Object to add
         """
         dir = os.path.join(self.path, obj.id[:2])
-        if not os.path.isdir(dir):
+        try:
             os.mkdir(dir)
+        except OSError, e:
+            if e.errno != errno.EEXIST:
+                raise
         path = os.path.join(dir, obj.id[2:])
         if os.path.exists(path):
             return # Already there, no need to write again
--
1.6.3.3

-- 
CLX Compute Cluster Developer (http://clx.see.ed.ac.uk/)
AL116, Alrick Building, King's Buildings. 0131 6505637
School of Engineering, University of Edinburgh

The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.

Attachment: signature.asc
Description: OpenPGP digital signature


Follow ups