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

Pass around the reactor explicitly #3385

Merged
merged 16 commits into from
Jun 22, 2018
Merged

Pass around the reactor explicitly #3385

merged 16 commits into from
Jun 22, 2018

Conversation

hawkowl
Copy link
Contributor

@hawkowl hawkowl commented Jun 12, 2018

This makes things easier to test down the road.

@@ -425,12 +427,12 @@ def _check_msisdn(self, authdict, _):

@defer.inlineCallbacks
def _check_dummy_auth(self, authdict, _):
yield run_on_reactor()
yield run_on_reactor(self.hs.get_clock())
Copy link
Member

Choose a reason for hiding this comment

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

frankly I think it would be easier to bin these than to fix them. I think they've been cargo-culted. don't mind though.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

They do seem a bit weird to me, to be honest. I don't really see any benefit to putting things back on the reactor thread...

Copy link
Member

Choose a reason for hiding this comment

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

the reasons for it now historical: back in the day (before various other things got fixed) you would get better stacktraces from deferreds which failed asynchronously than those that failed synchronously.



def run_on_reactor():
def run_on_reactor(clock=None):
Copy link
Member

Choose a reason for hiding this comment

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

can haz docstring for arg pls

@@ -404,7 +399,7 @@ class DeferredTimeoutError(Exception):
"""


def add_timeout_to_deferred(deferred, timeout, on_timeout_cancel=None):
def add_timeout_to_deferred(deferred, timeout, on_timeout_cancel=None, reactor=None):
Copy link
Member

Choose a reason for hiding this comment

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

can haz docstring for arg pls

Copy link
Member

Choose a reason for hiding this comment

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

looks like this will explode badly if called without a reactor param? might as well remove the default value

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

return make_deferred_yieldable(threads.deferToThread(_do_hash))
return make_deferred_yieldable(
threads.deferToThreadPool(
self.hs.get_reactor(), self.hs.get_reactor().getThreadPool(), _do_hash
Copy link
Member

Choose a reason for hiding this comment

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

trailing , pls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

@@ -858,7 +860,11 @@ def _do_hash():
return bcrypt.hashpw(password.encode('utf8') + self.hs.config.password_pepper,
bcrypt.gensalt(self.bcrypt_rounds))

return make_deferred_yieldable(threads.deferToThread(_do_hash))
return make_deferred_yieldable(
threads.deferToThreadPool(
Copy link
Member

Choose a reason for hiding this comment

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

why are we now using a threadpool here, ooi? (and what else does that threadpool do?)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

deferToThread implicitly uses the global reactor's threadpool -- so, this technically doesn't change behaviour, other than telling it explicitly what reactor (and what threadpool) we want to use. If we wished, we could add another threadpool explicitly for auth, here, rather than use the global one.

@@ -37,13 +37,15 @@ class MediaStorage(object):
"""Responsible for storing/fetching files from local sources.

Args:
hs (Homeserver)
Copy link
Member

Choose a reason for hiding this comment

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

synapse.server.HomeServer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

ratelimit, extra_users):
"""Send event to be handled on the master

Args:
clock (Clock)
Copy link
Member

Choose a reason for hiding this comment

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

it would be nice to try and get the types for these right, to help editors implement clickthrough etc. I believe this is a synapse.util.Clock ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -32,20 +32,15 @@
logger = logging.getLogger(__name__)


@defer.inlineCallbacks
def sleep(seconds):
Copy link
Member

Choose a reason for hiding this comment

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

I think you've missed a call to this in background_updates.py.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fix'd

@@ -34,9 +34,11 @@ class BackgroundFileConsumer(object):
# And resume once the size of the queue is less than this
_RESUME_ON_QUEUE_SIZE = 2

def __init__(self, file_obj):
def __init__(self, file_obj, reactor):
Copy link
Member

Choose a reason for hiding this comment

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

can haz docstring on arg pls

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@@ -58,6 +58,7 @@

class MediaRepository(object):
def __init__(self, hs):
self.hs = hs
Copy link
Member

Choose a reason for hiding this comment

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

this seems to be a bit redundant, but <shrug>

@hawkowl hawkowl dismissed richvdh’s stale review June 13, 2018 15:33

fixes made

@hawkowl hawkowl removed their assignment Jun 13, 2018
@hawkowl
Copy link
Contributor Author

hawkowl commented Jun 14, 2018

@richvdh This branch is now free of the run_on_reactor changes.

Copy link
Member

@richvdh richvdh left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -186,6 +190,9 @@ def setup(self):
self.datastore = DataStore(self.get_db_conn(), self)
logger.info("Finished setting up.")

def get_reactor(self):
Copy link
Member

Choose a reason for hiding this comment

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

I really wouldn't mind if this had a docstring; "Returns the twisted reactor in use by this HomeServer" or something?

@richvdh richvdh assigned hawkowl and unassigned richvdh Jun 20, 2018
@hawkowl hawkowl merged commit 77ac14b into develop Jun 22, 2018
@hawkowl hawkowl deleted the hawkowl/explicit-reactor branch June 22, 2018 08:37
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants