mirror of
https://github.com/jlu5/PyLink.git
synced 2025-03-28 18:36:59 +01:00
relay: only allow one thread to run initialize_channel at a time
Closes #529.
This commit is contained in:
parent
113bfcba9d
commit
b667bed1e6
@ -17,6 +17,7 @@ relayusers = defaultdict(dict)
|
|||||||
relayservers = defaultdict(dict)
|
relayservers = defaultdict(dict)
|
||||||
spawnlocks = defaultdict(threading.RLock)
|
spawnlocks = defaultdict(threading.RLock)
|
||||||
spawnlocks_servers = defaultdict(threading.RLock)
|
spawnlocks_servers = defaultdict(threading.RLock)
|
||||||
|
channels_init_in_progress = defaultdict(threading.Event)
|
||||||
|
|
||||||
dbname = conf.getDatabaseName('pylinkrelay')
|
dbname = conf.getDatabaseName('pylinkrelay')
|
||||||
datastore = structures.PickleDataStore('pylinkrelay', dbname)
|
datastore = structures.PickleDataStore('pylinkrelay', dbname)
|
||||||
@ -458,6 +459,7 @@ def get_remote_channel(irc, remoteirc, channel):
|
|||||||
|
|
||||||
def initialize_channel(irc, channel):
|
def initialize_channel(irc, channel):
|
||||||
"""Initializes a relay channel (merge local/remote users, set modes, etc.)."""
|
"""Initializes a relay channel (merge local/remote users, set modes, etc.)."""
|
||||||
|
|
||||||
# We're initializing a relay that already exists. This can be done at
|
# We're initializing a relay that already exists. This can be done at
|
||||||
# ENDBURST, or on the LINK command.
|
# ENDBURST, or on the LINK command.
|
||||||
relay = get_relay(irc, channel)
|
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)
|
log.debug('(%s) relay.initialize_channel: relay pair found to be %s', irc.name, relay)
|
||||||
queued_users = []
|
queued_users = []
|
||||||
if relay:
|
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 = db[relay]['links'].copy()
|
||||||
all_links.update((relay,))
|
all_links.update((relay,))
|
||||||
log.debug('(%s) relay.initialize_channel: all_links: %s', irc.name, all_links)
|
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:
|
if 'pylink' in world.services:
|
||||||
world.services['pylink'].join(irc, channel)
|
world.services['pylink'].join(irc, channel)
|
||||||
|
finally:
|
||||||
|
channels_init_in_progress[relay].clear()
|
||||||
|
|
||||||
def remove_channel(irc, channel):
|
def remove_channel(irc, channel):
|
||||||
"""Destroys a relay channel by parting all of its users."""
|
"""Destroys a relay channel by parting all of its users."""
|
||||||
|
Loading…
x
Reference in New Issue
Block a user