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 #4204 from matrix-org/rav/logcontext_leak_fixes
Browse files Browse the repository at this point in the history
Fix some logcontext leaks
  • Loading branch information
richvdh authored Nov 20, 2018
2 parents 31425d8 + 0c05da2 commit 416c671
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 7 deletions.
1 change: 1 addition & 0 deletions changelog.d/4204.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix logcontext leaks in EmailPusher and in tests
5 changes: 3 additions & 2 deletions synapse/push/mailer.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
)
from synapse.types import UserID
from synapse.util.async_helpers import concurrently_execute
from synapse.util.logcontext import make_deferred_yieldable
from synapse.visibility import filter_events_for_client

logger = logging.getLogger(__name__)
Expand Down Expand Up @@ -192,7 +193,7 @@ def _fetch_room_state(room_id):

logger.info("Sending email push notification to %s" % email_address)

yield self.sendmail(
yield make_deferred_yieldable(self.sendmail(
self.hs.config.email_smtp_host,
raw_from, raw_to, multipart_msg.as_string().encode('utf8'),
reactor=self.hs.get_reactor(),
Expand All @@ -201,7 +202,7 @@ def _fetch_room_state(room_id):
username=self.hs.config.email_smtp_user,
password=self.hs.config.email_smtp_pass,
requireTransportSecurity=self.hs.config.require_transport_security
)
))

@defer.inlineCallbacks
def get_room_vars(self, room_id, user_id, notifs, notif_events, room_state_ids):
Expand Down
3 changes: 2 additions & 1 deletion tests/push/test_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
from twisted.internet.defer import Deferred

from synapse.rest.client.v1 import admin, login, room
from synapse.util.logcontext import make_deferred_yieldable

from tests.unittest import HomeserverTestCase

Expand Down Expand Up @@ -47,7 +48,7 @@ def make_homeserver(self, reactor, clock):
def post_json_get_json(url, body):
d = Deferred()
self.push_attempts.append((d, url, body))
return d
return make_deferred_yieldable(d)

m.post_json_get_json = post_json_get_json

Expand Down
3 changes: 2 additions & 1 deletion tests/rest/media/v1/test_url_preview.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
from twisted.internet.defer import Deferred

from synapse.config.repository import MediaStorageProviderConfig
from synapse.util.logcontext import make_deferred_yieldable
from synapse.util.module_loader import load_module

from tests import unittest
Expand Down Expand Up @@ -77,7 +78,7 @@ def write_to(r):
d = Deferred()
d.addCallback(write_to)
self.fetches.append((d, url))
return d
return make_deferred_yieldable(d)

client = Mock()
client.get_file = get_file
Expand Down
4 changes: 2 additions & 2 deletions tests/test_federation.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def post_json(destination, path, data, headers=None, timeout=0):
"test.serv", lying_event, sent_to_us_directly=True
)

# Step the reactor, so the database fetches come back
self.reactor.advance(1)
# Step the reactor, so the database fetches come back
self.reactor.advance(1)

# on_receive_pdu should throw an error
failure = self.failureResultOf(d)
Expand Down
3 changes: 2 additions & 1 deletion tests/test_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
from synapse.http.server import JsonResource
from synapse.http.site import SynapseSite, logger
from synapse.util import Clock
from synapse.util.logcontext import make_deferred_yieldable

from tests import unittest
from tests.server import FakeTransport, make_request, render, setup_test_homeserver
Expand Down Expand Up @@ -95,7 +96,7 @@ def _callback(request, **kwargs):
d = Deferred()
d.addCallback(_throw)
self.reactor.callLater(1, d.callback, True)
return d
return make_deferred_yieldable(d)

res = JsonResource(self.homeserver)
res.register_paths("GET", [re.compile("^/_matrix/foo$")], _callback)
Expand Down

0 comments on commit 416c671

Please sign in to comment.