Fix inundation concurrency issues
This commit is contained in:
parent
eb97a47a25
commit
ed00fd73d1
|
@ -454,7 +454,7 @@ class WarningTLV(TLV):
|
||||||
def handle(self, user: Any, sender: Any) -> None:
|
def handle(self, user: Any, sender: Any) -> None:
|
||||||
user.add_message(f"warning: *A client warned you: {self.message}*"
|
user.add_message(f"warning: *A client warned you: {self.message}*"
|
||||||
if not user.squinnondation.no_markdown else
|
if not user.squinnondation.no_markdown else
|
||||||
f"warning: A client warned you: {self.message}")
|
"warning: A client warned you: {self.message}")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def construct(message: str) -> "WarningTLV":
|
def construct(message: str) -> "WarningTLV":
|
||||||
|
|
|
@ -662,14 +662,17 @@ class User(Peer):
|
||||||
"""
|
"""
|
||||||
Remove messages which are overdue (older than 2 minutes) from the inundation dictionnary.
|
Remove messages which are overdue (older than 2 minutes) from the inundation dictionnary.
|
||||||
"""
|
"""
|
||||||
|
self.data_lock.acquire()
|
||||||
for key in self.recent_messages:
|
for key in self.recent_messages:
|
||||||
if time.time() - self.recent_messages[key][1] > 120:
|
if time.time() - self.recent_messages[key][1] > 120:
|
||||||
self.recent_messages.pop(key)
|
self.recent_messages.pop(key)
|
||||||
|
self.data_lock.release()
|
||||||
|
|
||||||
def main_inundation(self) -> None:
|
def main_inundation(self) -> None:
|
||||||
"""
|
"""
|
||||||
The main inundation function.
|
The main inundation function.
|
||||||
"""
|
"""
|
||||||
|
self.data_lock.acquire()
|
||||||
for key in self.recent_messages:
|
for key in self.recent_messages:
|
||||||
k = list(self.recent_messages[key][2].keys())
|
k = list(self.recent_messages[key][2].keys())
|
||||||
for key2 in k:
|
for key2 in k:
|
||||||
|
@ -691,6 +694,7 @@ class User(Peer):
|
||||||
peer = self.recent_messages[key][2][key2][0]
|
peer = self.recent_messages[key][2][key2][0]
|
||||||
self.send_packet(peer, pkt)
|
self.send_packet(peer, pkt)
|
||||||
self.recent_messages[key][2].pop(key2)
|
self.recent_messages[key][2].pop(key2)
|
||||||
|
self.data_lock.release()
|
||||||
|
|
||||||
def add_system_message(self, msg: str, italic: bool = True, ignore_debug: bool = False) -> None:
|
def add_system_message(self, msg: str, italic: bool = True, ignore_debug: bool = False) -> None:
|
||||||
"""
|
"""
|
||||||
|
@ -1157,6 +1161,7 @@ class Inondator(Thread):
|
||||||
|
|
||||||
def run(self) -> None:
|
def run(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
try:
|
||||||
# clean the dictionnary
|
# clean the dictionnary
|
||||||
if time.time() - self.last_check > 30:
|
if time.time() - self.last_check > 30:
|
||||||
self.user.clean_inundation()
|
self.user.clean_inundation()
|
||||||
|
@ -1168,6 +1173,8 @@ class Inondator(Thread):
|
||||||
self.user.refresh_history()
|
self.user.refresh_history()
|
||||||
self.user.refresh_input()
|
self.user.refresh_input()
|
||||||
self.user.refresh_emoji_pad()
|
self.user.refresh_emoji_pad()
|
||||||
|
except Exception as e:
|
||||||
|
self.user.add_system_message(f"An error occured while inondating: {e}", ignore_debug=True)
|
||||||
|
|
||||||
# Avoid infinite loops
|
# Avoid infinite loops
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
Loading…
Reference in New Issue