From a2f02652e9db1b89e20924b0396724e6c77f00c1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Maurice=20Eisenbl=C3=A4tter?= Date: Mon, 6 May 2024 11:27:16 +0200 Subject: [PATCH] Fix possible deadlock in async packet processing (#2545) fix: start processing further packets if a packet is done --- .../protocol/async/AsyncFilterManager.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java index 7765b0d3..c77c4d19 100644 --- a/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java +++ b/src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java @@ -428,7 +428,7 @@ public class AsyncFilterManager implements AsynchronousManager { } // There are no more listeners - queue the packet for transmission - signalFreeProcessingSlot(packet); + signalFreeProcessingSlot(packet, onMainThread); PacketSendingQueue queue = getSendingQueue(packet, false); @@ -467,11 +467,18 @@ public class AsyncFilterManager implements AsynchronousManager { } /** - * Signal that a packet has finished processing. + * Signal that a packet has finished processing. Tries to process further packets + * if a processing slot is still free. * @param packet - packet to signal. + * @param onMainThread whether or not this method was run by the main thread. */ - public void signalFreeProcessingSlot(PacketEvent packet) { - getProcessingQueue(packet).signalProcessingDone(); + public void signalFreeProcessingSlot(PacketEvent packet, boolean onMainThread) { + PacketProcessingQueue queue = getProcessingQueue(packet); + // mark slot as done + queue.signalProcessingDone(); + + // start processing next slot if possible + queue.signalBeginProcessing(onMainThread); } /**