From de6cd8d9f1cb62f34f6a597f9578ecd0d11e9f3a Mon Sep 17 00:00:00 2001 From: Alexandre Beloin Date: Sun, 8 Feb 2015 20:01:30 -0500 Subject: [PATCH 1/3] Added detection of fs unsupported link creation. Function acquire will run in infinite loop if the fs doesn't support link creation(OSError: (38, 'Function not implemented')) --- lib/lockfile/linklockfile.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/lockfile/linklockfile.py b/lib/lockfile/linklockfile.py index 9c506734..d407848c 100644 --- a/lib/lockfile/linklockfile.py +++ b/lib/lockfile/linklockfile.py @@ -28,7 +28,9 @@ class LinkLockFile(LockBase): # Try and create a hard link to it. try: os.link(self.unique_name, self.lock_file) - except OSError: + except OSError as e: + if e.errno == 38: + raise LockFailed("%s" % e.strerror) # Link creation failed. Maybe we've double-locked? nlinks = os.stat(self.unique_name).st_nlink if nlinks == 2: From b283015d38d33aa43568336926947ea95b3351ee Mon Sep 17 00:00:00 2001 From: Alexandre Beloin Date: Sun, 8 Feb 2015 20:07:52 -0500 Subject: [PATCH 2/3] Use errno.ENOSYS instead of 38. --- lib/lockfile/linklockfile.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/lockfile/linklockfile.py b/lib/lockfile/linklockfile.py index d407848c..770350f2 100644 --- a/lib/lockfile/linklockfile.py +++ b/lib/lockfile/linklockfile.py @@ -5,6 +5,7 @@ import os from . import (LockBase, LockFailed, NotLocked, NotMyLock, LockTimeout, AlreadyLocked) +import errno class LinkLockFile(LockBase): """Lock access to a file using atomic property of link(2). @@ -29,7 +30,7 @@ class LinkLockFile(LockBase): try: os.link(self.unique_name, self.lock_file) except OSError as e: - if e.errno == 38: + if e.errno == errno.ENOSYS: raise LockFailed("%s" % e.strerror) # Link creation failed. Maybe we've double-locked? nlinks = os.stat(self.unique_name).st_nlink From c5cfede6382a7a29356b3ceaa3f1513cb16f4fe0 Mon Sep 17 00:00:00 2001 From: Alexandre Beloin Date: Mon, 9 Feb 2015 14:07:40 -0500 Subject: [PATCH 3/3] Catch exception if unable to cache the response --- lib/cachecontrol/adapter.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/cachecontrol/adapter.py b/lib/cachecontrol/adapter.py index d2ca7e87..b43b0f06 100644 --- a/lib/cachecontrol/adapter.py +++ b/lib/cachecontrol/adapter.py @@ -58,7 +58,11 @@ class CacheControlAdapter(HTTPAdapter): response = cached_response else: # try to cache the response - self.controller.cache_response(request, response) + try: + self.controller.cache_response(request, response) + except Exception as e: + # Failed to cache the results + pass resp = super(CacheControlAdapter, self).build_response( request, response