Skip to content

Commit c9b3780

Browse files
committed
Race condition with pre-existing rows.
1 parent 9cecd78 commit c9b3780

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

core/pubsub.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,19 @@ async def subscribe(self):
149149
async with await AsyncConnection.connect(self.url, autocommit=True) as conn:
150150
async with conn.cursor() as cursor:
151151
# preprocess all rows that might be there
152+
async for row in await cursor.execute(sql.SQL("""
153+
WITH to_delete AS (
154+
SELECT id
155+
FROM {table}
156+
WHERE guild_id = %s
157+
AND node = %s
158+
ORDER BY id
159+
)
160+
DELETE FROM {table}
161+
WHERE id IN (SELECT id FROM to_delete)
162+
RETURNING id
163+
""").format(table=sql.Identifier(self.name)), (self.node.guild_id, self.node.name)):
164+
self.read_queue.put_nowait(row['id'])
152165
await cursor.execute(sql.SQL("LISTEN {table}").format(table=sql.Identifier(self.name)))
153166
gen = conn.notifies()
154167
async for n in gen:

0 commit comments

Comments
 (0)