Fall back to read-only credentials on EACCES errors

This change fixes a bug where multiple threads and/or processes
using multistore_file on Windows to access the same backing
store could raise IOError errno.EACCES to the calling application.
This change causes a fallback to read only mode and refreshes
credentials if necessary.
This commit is contained in:
Travis Hobrla
2016-01-28 10:53:24 -08:00
parent 0b6e72ea09
commit 4f5a9baa08
2 changed files with 4 additions and 1 deletions

View File

@@ -293,6 +293,8 @@ class _MultiStore(object):
elif e.errno == errno.EDEADLK: elif e.errno == errno.EDEADLK:
logger.warn('Lock contention on multistore file, opening ' logger.warn('Lock contention on multistore file, opening '
'in read-only mode.') 'in read-only mode.')
elif e.errno == errno.EACCES:
logger.warn('Cannot access credentials file.')
else: else:
raise raise
if not self._file.is_locked(): if not self._file.is_locked():

View File

@@ -82,7 +82,8 @@ class MultistoreFileTests(unittest.TestCase):
os.close(filehandle) os.close(filehandle)
try: try:
for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK): for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK,
errno.EACCES):
multistore = multistore_file._MultiStore(filename) multistore = multistore_file._MultiStore(filename)
multistore._file = _MockLockedFile(filename, error_code) multistore._file = _MockLockedFile(filename, error_code)
# Should not raise even though the underlying file class did. # Should not raise even though the underlying file class did.