3
0
mirror of https://github.com/jlu5/PyLink.git synced 2024-12-24 19:52:53 +01:00

relay: only allow one thread to run initialize_channel at a time

Closes #529.
This commit is contained in:
James Lu 2017-09-23 13:58:15 -07:00
parent 113bfcba9d
commit b667bed1e6

View File

@ -17,6 +17,7 @@ relayusers = defaultdict(dict)
relayservers = defaultdict(dict)
spawnlocks = defaultdict(threading.RLock)
spawnlocks_servers = defaultdict(threading.RLock)
channels_init_in_progress = defaultdict(threading.Event)
dbname = conf.getDatabaseName('pylinkrelay')
datastore = structures.PickleDataStore('pylinkrelay', dbname)
@ -458,6 +459,7 @@ def get_remote_channel(irc, remoteirc, channel):
def initialize_channel(irc, channel):
"""Initializes a relay channel (merge local/remote users, set modes, etc.)."""
# We're initializing a relay that already exists. This can be done at
# ENDBURST, or on the LINK command.
relay = get_relay(irc, channel)
@ -465,6 +467,12 @@ def initialize_channel(irc, channel):
log.debug('(%s) relay.initialize_channel: relay pair found to be %s', irc.name, relay)
queued_users = []
if relay:
if relay in channels_init_in_progress and channels_init_in_progress[relay].is_set():
log.debug('(%s) relay.initialize_channel: skipping init of %s since another one is in progress', irc.name, relay)
return
channels_init_in_progress[relay].set()
try:
all_links = db[relay]['links'].copy()
all_links.update((relay,))
log.debug('(%s) relay.initialize_channel: all_links: %s', irc.name, all_links)
@ -500,6 +508,8 @@ def initialize_channel(irc, channel):
if 'pylink' in world.services:
world.services['pylink'].join(irc, channel)
finally:
channels_init_in_progress[relay].clear()
def remove_channel(irc, channel):
"""Destroys a relay channel by parting all of its users."""