Skip to content

Commit b12db39

Browse files
committed
chan_track: Ensure the hooks acquire their locks
1 parent c7c6890 commit b12db39

File tree

2 files changed

+23
-19
lines changed

2 files changed

+23
-19
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2828
- Fixed handling of colons in core IRC parser
2929
- Fix FML random URL
3030
- Ensure hooks are triggered according to priority
31+
- chan_track: Ensure hooks acquire the needed locks
3132
### Removed
3233
- twitch.py removed due to outdated API and lack of maintainer
3334
- Remove unused run_before events/tasks

plugins/core/chan_track.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
Requires:
55
server_info.py
66
"""
7+
import asyncio
78
import gc
89
import json
910
import logging
@@ -26,6 +27,8 @@
2627

2728
logger = logging.getLogger("cloudbot")
2829

30+
data_lock = asyncio.Lock()
31+
2932

3033
class WeakDict(dict):
3134
"""
@@ -520,7 +523,7 @@ def replace_user_data(conn, chan_data):
520523
del chan_data.users[old_nick]
521524

522525

523-
@hook.irc_raw(['353', '366'], singlethread=True, do_sieve=False)
526+
@hook.irc_raw(['353', '366'], singlethread=True, lock=data_lock, do_sieve=False)
524527
def on_names(conn, irc_paramlist, irc_command):
525528
"""
526529
:type conn: cloudbot.client.Client
@@ -596,7 +599,7 @@ def serialize(self, mapping, **kwargs):
596599
return json.dumps(self._serialize(mapping), **kwargs)
597600

598601

599-
@hook.permission("chanop")
602+
@hook.permission("chanop", lock=data_lock, do_sieve=False)
600603
def perm_check(chan, conn, nick):
601604
"""
602605
:type chan: str
@@ -687,7 +690,7 @@ def getdata_cmd(conn, chan, nick):
687690
return web.paste(MappingSerializer().serialize(memb, indent=2))
688691

689692

690-
@hook.irc_raw(['PRIVMSG', 'NOTICE'], do_sieve=False)
693+
@hook.irc_raw(['PRIVMSG', 'NOTICE'], lock=data_lock, do_sieve=False)
691694
def on_msg(conn, nick, user, host, irc_paramlist):
692695
chan, *other_data = irc_paramlist
693696

@@ -711,7 +714,7 @@ def on_msg(conn, nick, user, host, irc_paramlist):
711714
memb.data['last_privmsg'] = time.time()
712715

713716

714-
@hook.periodic(600)
717+
@hook.periodic(600, lock=data_lock, do_sieve=False)
715718
def clean_pms(bot):
716719
cutoff = time.time() - 600
717720
for conn in bot.connections.values():
@@ -728,7 +731,7 @@ def clean_pms(bot):
728731
pass
729732

730733

731-
@hook.irc_raw('JOIN', do_sieve=False)
734+
@hook.irc_raw('JOIN', lock=data_lock, do_sieve=False)
732735
def on_join(nick, user, host, conn, irc_paramlist):
733736
"""
734737
:type nick: str
@@ -784,7 +787,7 @@ def _parse_mode_string(modes, params, status_modes, mode_types):
784787
return new_modes
785788

786789

787-
@hook.irc_raw('MODE', do_sieve=False)
790+
@hook.irc_raw('MODE', lock=data_lock, do_sieve=False)
788791
def on_mode(chan, irc_paramlist, conn):
789792
"""
790793
:type chan: str
@@ -823,7 +826,7 @@ def on_mode(chan, irc_paramlist, conn):
823826
member.sort_status()
824827

825828

826-
@hook.irc_raw('PART', do_sieve=False)
829+
@hook.irc_raw('PART', lock=data_lock, do_sieve=False)
827830
def on_part(chan, nick, conn):
828831
"""
829832
:type chan: str
@@ -838,7 +841,7 @@ def on_part(chan, nick, conn):
838841
del chan_data.users[nick]
839842

840843

841-
@hook.irc_raw('KICK', do_sieve=False)
844+
@hook.irc_raw('KICK', lock=data_lock, do_sieve=False)
842845
def on_kick(chan, target, conn):
843846
"""
844847
:type chan: str
@@ -848,7 +851,7 @@ def on_kick(chan, target, conn):
848851
on_part(chan, target, conn)
849852

850853

851-
@hook.irc_raw('QUIT', do_sieve=False)
854+
@hook.irc_raw('QUIT', lock=data_lock, do_sieve=False)
852855
def on_quit(nick, conn):
853856
"""
854857
:type nick: str
@@ -862,7 +865,7 @@ def on_quit(nick, conn):
862865
del chan.users[nick]
863866

864867

865-
@hook.irc_raw('NICK', do_sieve=False)
868+
@hook.irc_raw('NICK', lock=data_lock, do_sieve=False)
866869
def on_nick(nick, irc_paramlist, conn):
867870
"""
868871
:type nick: str
@@ -889,7 +892,7 @@ def on_nick(nick, irc_paramlist, conn):
889892
user_chans[new_nick] = user_chans.pop(nick)
890893

891894

892-
@hook.irc_raw('ACCOUNT', do_sieve=False)
895+
@hook.irc_raw('ACCOUNT', lock=data_lock, do_sieve=False)
893896
def on_account(conn, nick, irc_paramlist):
894897
"""
895898
:type nick: str
@@ -899,7 +902,7 @@ def on_account(conn, nick, irc_paramlist):
899902
get_users(conn).getuser(nick).account = irc_paramlist[0]
900903

901904

902-
@hook.irc_raw('CHGHOST', do_sieve=False)
905+
@hook.irc_raw('CHGHOST', lock=data_lock, do_sieve=False)
903906
def on_chghost(conn, nick, irc_paramlist):
904907
"""
905908
:type nick: str
@@ -912,7 +915,7 @@ def on_chghost(conn, nick, irc_paramlist):
912915
user.host = host
913916

914917

915-
@hook.irc_raw('AWAY', do_sieve=False)
918+
@hook.irc_raw('AWAY', lock=data_lock, do_sieve=False)
916919
def on_away(conn, nick, irc_paramlist):
917920
"""
918921
:type nick: str
@@ -929,7 +932,7 @@ def on_away(conn, nick, irc_paramlist):
929932
user.away_message = reason
930933

931934

932-
@hook.irc_raw('352', do_sieve=False)
935+
@hook.irc_raw('352', lock=data_lock, do_sieve=False)
933936
def on_who(conn, irc_paramlist):
934937
"""
935938
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -949,7 +952,7 @@ def on_who(conn, irc_paramlist):
949952
user.is_oper = is_oper
950953

951954

952-
@hook.irc_raw('311', do_sieve=False)
955+
@hook.irc_raw('311', lock=data_lock, do_sieve=False)
953956
def on_whois_name(conn, irc_paramlist):
954957
"""
955958
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -962,7 +965,7 @@ def on_whois_name(conn, irc_paramlist):
962965
user.realname = realname
963966

964967

965-
@hook.irc_raw('330', do_sieve=False)
968+
@hook.irc_raw('330', lock=data_lock, do_sieve=False)
966969
def on_whois_acct(conn, irc_paramlist):
967970
"""
968971
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -972,7 +975,7 @@ def on_whois_acct(conn, irc_paramlist):
972975
get_users(conn).getuser(nick).account = acct
973976

974977

975-
@hook.irc_raw('301', do_sieve=False)
978+
@hook.irc_raw('301', lock=data_lock, do_sieve=False)
976979
def on_whois_away(conn, irc_paramlist):
977980
"""
978981
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -984,7 +987,7 @@ def on_whois_away(conn, irc_paramlist):
984987
user.away_message = msg
985988

986989

987-
@hook.irc_raw('312', do_sieve=False)
990+
@hook.irc_raw('312', lock=data_lock, do_sieve=False)
988991
def on_whois_server(conn, irc_paramlist):
989992
"""
990993
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList
@@ -994,7 +997,7 @@ def on_whois_server(conn, irc_paramlist):
994997
get_users(conn).getuser(nick).server = server
995998

996999

997-
@hook.irc_raw('313', do_sieve=False)
1000+
@hook.irc_raw('313', lock=data_lock, do_sieve=False)
9981001
def on_whois_oper(conn, irc_paramlist):
9991002
"""
10001003
:type irc_paramlist: cloudbot.util.parsers.irc.ParamList

0 commit comments

Comments
 (0)