Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #2631 from xyzz/fix_appservice_event_backlog
Browse files Browse the repository at this point in the history
Fix appservices being backlogged and not receiving new events due to a bug in notify_interested_services
  • Loading branch information
erikjohnston authored Nov 8, 2017
2 parents 167eb01 + d46386d commit d305987
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 1 addition & 5 deletions synapse/handlers/appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,10 @@ def notify_interested_services(self, current_id):
with Measure(self.clock, "notify_interested_services"):
self.is_processing = True
try:
upper_bound = self.current_max
limit = 100
while True:
upper_bound, events = yield self.store.get_new_events_for_appservice(
upper_bound, limit
self.current_max, limit
)

if not events:
Expand Down Expand Up @@ -105,9 +104,6 @@ def notify_interested_services(self, current_id):
)

yield self.store.set_appservice_last_pos(upper_bound)

if len(events) < limit:
break
finally:
self.is_processing = False

Expand Down
15 changes: 12 additions & 3 deletions tests/handlers/test_appservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ def test_notify_interested_services(self):
type="m.room.message",
room_id="!foo:bar"
)
self.mock_store.get_new_events_for_appservice.return_value = (0, [event])
self.mock_store.get_new_events_for_appservice.side_effect = [
(0, [event]),
(0, [])
]
self.mock_as_api.push = Mock()
yield self.handler.notify_interested_services(0)
self.mock_scheduler.submit_event_for_as.assert_called_once_with(
Expand All @@ -75,7 +78,10 @@ def test_query_user_exists_unknown_user(self):
)
self.mock_as_api.push = Mock()
self.mock_as_api.query_user = Mock()
self.mock_store.get_new_events_for_appservice.return_value = (0, [event])
self.mock_store.get_new_events_for_appservice.side_effect = [
(0, [event]),
(0, [])
]
yield self.handler.notify_interested_services(0)
self.mock_as_api.query_user.assert_called_once_with(
services[0], user_id
Expand All @@ -98,7 +104,10 @@ def test_query_user_exists_known_user(self):
)
self.mock_as_api.push = Mock()
self.mock_as_api.query_user = Mock()
self.mock_store.get_new_events_for_appservice.return_value = (0, [event])
self.mock_store.get_new_events_for_appservice.side_effect = [
(0, [event]),
(0, [])
]
yield self.handler.notify_interested_services(0)
self.assertFalse(
self.mock_as_api.query_user.called,
Expand Down

0 comments on commit d305987

Please sign in to comment.