Skip to content
This repository has been archived by the owner on Nov 5, 2019. It is now read-only.

Commit

Permalink
Merge pull request #336 from thobrla/master
Browse files Browse the repository at this point in the history
Fall back to credential refresh on EDEADLK
  • Loading branch information
dhermes committed Nov 18, 2015
2 parents ab3e535 + 3b72d50 commit 42279ca
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 0 deletions.
3 changes: 3 additions & 0 deletions oauth2client/multistore_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,9 @@ def _lock(self):
elif e.errno == errno.ENOLCK:
logger.warn('File system is out of resources for writing the '
'credentials file (is your disk full?).')
elif e.errno == errno.EDEADLK:
logger.warn('Lock contention on multistore file, opening '
'in read-only mode.')
else:
raise
if not self._file.is_locked():
Expand Down
43 changes: 43 additions & 0 deletions tests/test_multistore_file.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Unit tests for oauth2client.multistore_file."""

import errno
import os
import tempfile
import unittest

from oauth2client import multistore_file


class _MockLockedFile(object):

def __init__(self, filename_str, error_code):
self.filename_str = filename_str
self.error_code = error_code
self.open_and_lock_called = False

def open_and_lock(self):
self.open_and_lock_called = True
raise IOError(self.error_code, '')

def is_locked(self):
return False

def filename(self):
return self.filename_str


class MultistoreFileTests(unittest.TestCase):

def test_lock_file_raises_ioerror(self):
filehandle, filename = tempfile.mkstemp()
os.close(filehandle)

try:
for error_code in (errno.EDEADLK, errno.ENOSYS, errno.ENOLCK):
multistore = multistore_file._MultiStore(filename)
multistore._file = _MockLockedFile(filename, error_code)
# Should not raise even though the underlying file class did.
multistore._lock()
self.assertTrue(multistore._file.open_and_lock_called)
finally:
os.unlink(filename)

0 comments on commit 42279ca

Please sign in to comment.