Skip to content

Commit

Permalink
Quarantine on IOErrors while reading
Browse files Browse the repository at this point in the history
Change-Id: I3b89d10096f29652f691428065b9801d57d77ec7
  • Loading branch information
tipabu committed Jul 2, 2021
1 parent 977f1bc commit f25592f
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 1 deletion.
10 changes: 9 additions & 1 deletion swift/obj/diskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2063,7 +2063,15 @@ def __iter__(self):
self._read_to_eof = False
self._init_checks()
while True:
chunk = self._fp.read(self._disk_chunk_size)
try:
chunk = self._fp.read(self._disk_chunk_size)
except IOError as e:
if e.errno == errno.EIO:
# Note that if there's no quarantine hook set up,
# this won't raise any exception
self._quarantine(str(e))
# ... so it's significant that this is not in an else
raise
if chunk:
self._update_checks(chunk)
self._bytes_read += len(chunk)
Expand Down
28 changes: 28 additions & 0 deletions test/unit/obj/test_diskfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3924,6 +3924,34 @@ def raise_dfq(m):
reader._obj_size += 1
self.assertRaises(DiskFileQuarantined, b''.join, reader)

def test_disk_file_reader_iter_w_io_error(self):
df, df_data = self._create_test_file(b'1234567890')

class FakeFp(object):
def __init__(self, buf):
self.pos = 0
self.buf = buf

def read(self, sz):
if not self.buf:
raise IOError(5, 'Input/output error')
chunk, self.buf = self.buf, b''
self.pos += len(chunk)
return chunk

def close(self):
pass

def tell(self):
return self.pos

def raise_dfq(m):
raise DiskFileQuarantined(m)

reader = df.reader(_quarantine_hook=raise_dfq)
reader._fp = FakeFp(b'1234')
self.assertRaises(DiskFileQuarantined, b''.join, reader)

def test_disk_file_app_iter_corners(self):
df, df_data = self._create_test_file(b'1234567890')
quarantine_msgs = []
Expand Down

0 comments on commit f25592f

Please sign in to comment.