Skip to content

Commit

Permalink
Fix possible deadlock in async packet processing (#2545)
Browse files Browse the repository at this point in the history
fix: start processing further packets if a packet is done
  • Loading branch information
Ingrim4 authored May 6, 2024
1 parent f9d3266 commit a2f0265
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/com/comphenix/protocol/async/AsyncFilterManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ private void signalPacketTransmission(PacketEvent packet, boolean onMainThread)
}

// There are no more listeners - queue the packet for transmission
signalFreeProcessingSlot(packet);
signalFreeProcessingSlot(packet, onMainThread);

PacketSendingQueue queue = getSendingQueue(packet, false);

Expand Down Expand Up @@ -467,11 +467,18 @@ public PacketProcessingQueue getProcessingQueue(PacketEvent packet) {
}

/**
* 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);
}

/**
Expand Down

0 comments on commit a2f0265

Please sign in to comment.