Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 45af4c3

Browse files
committed
Iterate over skipped changes lines
Change the structure of Feed.next() and InfiniteFeed.next() to iterate over skipped lines in the feed rather than recursing. This fixes #245 where recursion can cause a stack overflow.
1 parent 36b63a2 commit 45af4c3

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

CHANGES.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
==================
33
- [FIXED] Resolved issue where generated UUIDs for replication documents would
44
not be converted to strings.
5+
- [FIXED] Resolved issue where database.infinite_changes() method can cause a stack overflow.
56

67
2.3.0 (2016-11-02)
78
==================

src/cloudant/feed.py

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -155,13 +155,14 @@ def next(self):
155155
156156
:returns: Data representing what was seen in the feed
157157
"""
158-
if not self._resp:
159-
self._start()
160-
if self._stop:
161-
raise StopIteration
162-
skip, data = self._process_data(next_(self._lines))
163-
if skip:
164-
return self.next()
158+
while True:
159+
if not self._resp:
160+
self._start()
161+
if self._stop:
162+
raise StopIteration
163+
skip, data = self._process_data(next_(self._lines))
164+
if not skip:
165+
break
165166
return data
166167

167168
def _process_data(self, line):
@@ -249,11 +250,19 @@ def next(self):
249250
250251
:returns: Data representing what was seen in the feed
251252
"""
252-
if self._source == 'CouchDB':
253-
raise CloudantException(
254-
'Infinite _db_updates feed not supported for CouchDB.')
255-
if self._last_seq:
256-
self._options.update({'since': self._last_seq})
257-
self._resp = None
258-
self._last_seq = None
259-
return super(InfiniteFeed, self).next()
253+
while True:
254+
if self._source == 'CouchDB':
255+
raise CloudantException(
256+
'Infinite _db_updates feed not supported for CouchDB.')
257+
if self._last_seq:
258+
self._options.update({'since': self._last_seq})
259+
self._resp = None
260+
self._last_seq = None
261+
if not self._resp:
262+
self._start()
263+
if self._stop:
264+
raise StopIteration
265+
skip, data = self._process_data(next_(self._lines))
266+
if not skip:
267+
break
268+
return data

0 commit comments

Comments
 (0)