From ad4088d97c6fab6b901a2dfab2e088fe79e3b5e3 Mon Sep 17 00:00:00 2001 From: Devon Hudson Date: Mon, 3 Feb 2025 17:01:25 -0700 Subject: [PATCH] Change tactic so we don't break APNS pushkins --- sygnal/gcmpushkin.py | 7 ++++++- sygnal/sygnal.py | 7 ++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/sygnal/gcmpushkin.py b/sygnal/gcmpushkin.py index b454da06..575a2350 100644 --- a/sygnal/gcmpushkin.py +++ b/sygnal/gcmpushkin.py @@ -240,9 +240,14 @@ async def create( # set the usual env var and use `trust_env=True` os.environ["HTTPS_PROXY"] = proxy_url + # Ensure the asyncio reactor has started the event loop. + loop = asyncio.get_event_loop() + # ClientSession must be instantiated by an async function, hence we do this # here instead of `__init__`. - session = aiohttp.ClientSession(trust_env=True, auto_decompress=False) + session = aiohttp.ClientSession( + trust_env=True, auto_decompress=False, loop=loop + ) cls.google_auth_request = google.auth.transport._aiohttp_requests.Request( session=session diff --git a/sygnal/sygnal.py b/sygnal/sygnal.py index f7901d5a..2921e1f6 100644 --- a/sygnal/sygnal.py +++ b/sygnal/sygnal.py @@ -14,7 +14,6 @@ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. -import asyncio import copy import importlib import logging @@ -29,7 +28,7 @@ from opentracing import Tracer from opentracing.scope_managers.asyncio import AsyncioScopeManager from twisted.internet import asyncioreactor, defer -from twisted.internet.defer import Deferred +from twisted.internet.defer import Deferred, ensureDeferred from twisted.internet.interfaces import ( IReactorCore, IReactorFDSet, @@ -226,9 +225,7 @@ def run(self) -> None: @defer.inlineCallbacks def start() -> Generator[Deferred[Any], Any, Any]: try: - yield Deferred.fromFuture( - asyncio.ensure_future(self.make_pushkins_then_start()) - ) + yield ensureDeferred(self.make_pushkins_then_start()) except Exception: # Print the exception and bail out. print("Error during startup:", file=sys.stderr)