From 4f5a9baa083e69605c3aeaa7435e278c75f78b3a Mon Sep 17 00:00:00 2001 From: Travis Hobrla Date: Thu, 28 Jan 2016 10:53:24 -0800 Subject: [PATCH] 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. --- oauth2client/contrib/multistore_file.py | 2 ++ tests/contrib/test_multistore_file.py | 3 ++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/oauth2client/contrib/multistore_file.py b/oauth2client/contrib/multistore_file.py index 13bd440..d1ef51c 100644 --- a/oauth2client/contrib/multistore_file.py +++ b/oauth2client/contrib/multistore_file.py @@ -293,6 +293,8 @@ class _MultiStore(object): elif e.errno == errno.EDEADLK: logger.warn('Lock contention on multistore file, opening ' 'in read-only mode.') + elif e.errno == errno.EACCES: + logger.warn('Cannot access credentials file.') else: raise if not self._file.is_locked(): diff --git a/tests/contrib/test_multistore_file.py b/tests/contrib/test_multistore_file.py index 8cbe0c6..5e1fe77 100644 --- a/tests/contrib/test_multistore_file.py +++ b/tests/contrib/test_multistore_file.py @@ -82,7 +82,8 @@ class MultistoreFileTests(unittest.TestCase): os.close(filehandle) 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._file = _MockLockedFile(filename, error_code) # Should not raise even though the underlying file class did.