Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/14092.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Run the integration test suites with the asyncio reactor enabled in CI.
26 changes: 12 additions & 14 deletions synapse/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,30 @@
import sys

from synapse.util.rust import check_rust_lib_up_to_date
from synapse.util.stringutils import strtobool

# Check that we're not running on an unsupported Python version.
if sys.version_info < (3, 7):
print("Synapse requires Python 3.7 or above.")
sys.exit(1)

# Allow using the asyncio reactor via env var.
if bool(os.environ.get("SYNAPSE_ASYNC_IO_REACTOR", False)):
try:
from incremental import Version
if strtobool(os.environ.get("SYNAPSE_ASYNC_IO_REACTOR", "0")):
from incremental import Version

import twisted
import twisted

# We need a bugfix that is included in Twisted 21.2.0:
# https://twistedmatrix.com/trac/ticket/9787
if twisted.version < Version("Twisted", 21, 2, 0):
print("Using asyncio reactor requires Twisted>=21.2.0")
sys.exit(1)
# We need a bugfix that is included in Twisted 21.2.0:
# https://twistedmatrix.com/trac/ticket/9787
if twisted.version < Version("Twisted", 21, 2, 0):
print("Using asyncio reactor requires Twisted>=21.2.0")
sys.exit(1)

import asyncio
import asyncio

from twisted.internet import asyncioreactor
from twisted.internet import asyncioreactor

asyncioreactor.install(asyncio.get_event_loop())
except ImportError:
pass
Comment on lines -48 to -49
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure what we were hoping to capture in #12135, but we may as well fail loudly. And besides, this is all still experimental.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See #12135 (comment) for why this is in a try-except.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CI was fully green on this PR. I guess we had to fixup whatever that comment was talking about as part of the Rust work in #12595 et al?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe! Not sure. 🤷

asyncioreactor.install(asyncio.get_event_loop())

# Twisted and canonicaljson will fail to import when this file is executed to
# get the __version__ during a fresh install. That's OK and subsequent calls to
Expand Down
3 changes: 3 additions & 0 deletions synapse/config/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,8 @@ def setup_logging(
logBeginner: The Twisted logBeginner to use.

"""
from twisted.internet import reactor

log_config_path = (
config.worker.worker_log_config
if use_worker_options
Expand All @@ -348,3 +350,4 @@ def setup_logging(
)
logging.info("Server hostname: %s", config.server.server_name)
logging.info("Instance name: %s", hs.get_instance_name())
logging.info("Twisted reactor: %s", type(reactor).__name__)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm assuming that we need to install the asyncio reactor first before we do this? But that should have already happened at import time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's right, the reactor gets installed quite early