From 37123e33d2f07bcc270a5b574863d0f1483451d8 Mon Sep 17 00:00:00 2001 From: ed Date: Sun, 8 Mar 2026 10:08:56 +0000 Subject: [PATCH] forget_ip: fix cursor locking --- copyparty/up2k.py | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/copyparty/up2k.py b/copyparty/up2k.py index 3fa7f092..7aed0f4a 100644 --- a/copyparty/up2k.py +++ b/copyparty/up2k.py @@ -661,19 +661,20 @@ class Up2k(object): for _ in range(2): q = "select ip, at from up where ip > '' order by +at limit 1" - hits = cur.execute(q).fetchall() - if not hits: - break + with self.mutex: + hits = cur.execute(q).fetchall() + if not hits: + break - remains = hits[0][1] - cutoff - if remains > 0: - timeout = min(timeout, now + remains) - break + remains = hits[0][1] - cutoff + if remains > 0: + timeout = min(timeout, now + remains) + break - q = "update up set ip = '' where ip > '' and at <= %d" - cur.execute(q % (cutoff,)) - zi = cur.rowcount - cur.connection.commit() + q = "update up set ip = '' where ip > '' and at <= %d" + cur.execute(q % (cutoff,)) + zi = cur.rowcount + cur.connection.commit() t = "forget-ip(%d) removed %d IPs from db [/%s]" self.log(t % (maxage, zi, vol.vpath))