Skip to content

Commit

Permalink
Add Timeout to CompletableFuture in GeyserBungeePingPassthrough to Pr…
Browse files Browse the repository at this point in the history
…event Memory Leak (GeyserMC#4858)

* fix: Add timeout for GeyserBungeePingPassthrough#getPingInformation

Signed-off-by: ByteExceptionM <git@byteexception.eu>

* fix: Use Geyser Logger instead of Bungee Logger

Signed-off-by: ByteExceptionM <git@byteexception.eu>

* Fix typo

Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>

* chore: Add ip suppression if configured

Signed-off-by: ByteExceptionM <git@byteexception.eu>

* Remove empty line

Co-authored-by: chris <github@onechris.mozmail.com>

* Remove empty line

Co-authored-by: chris <github@onechris.mozmail.com>

---------

Signed-off-by: ByteExceptionM <git@byteexception.eu>
Co-authored-by: Konicai <71294714+Konicai@users.noreply.github.com>
Co-authored-by: chris <github@onechris.mozmail.com>
  • Loading branch information
3 people authored Jul 16, 2024
1 parent 305495c commit 677a56c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,15 @@
import net.md_5.bungee.api.plugin.Listener;
import net.md_5.bungee.protocol.ProtocolConstants;
import org.checkerframework.checker.nullness.qual.Nullable;
import org.geysermc.geyser.GeyserImpl;
import org.geysermc.geyser.ping.GeyserPingInfo;
import org.geysermc.geyser.ping.IGeyserPingPassthrough;

import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.util.UUID;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.TimeUnit;

@AllArgsConstructor
public class GeyserBungeePingPassthrough implements IGeyserPingPassthrough, Listener {
Expand All @@ -59,7 +61,17 @@ public GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress) {
future.complete(event);
}
}));
ProxyPingEvent event = future.join();

ProxyPingEvent event;

try {
event = future.get(100, TimeUnit.MILLISECONDS);
} catch (Throwable cause) {
String address = GeyserImpl.getInstance().getConfig().isLogPlayerIpAddresses() ? inetSocketAddress.toString() : "<IP address withheld>";
GeyserImpl.getInstance().getLogger().error("Failed to get ping information for " + address, cause);
return null;
}

ServerPing response = event.getResponse();
return new GeyserPingInfo(
response.getDescriptionComponent().toLegacyText(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@
public interface IGeyserPingPassthrough {

/**
* Get the MOTD of the server displayed on the multiplayer screen
* Gets the ping information, including the MOTD and player count, from the server
*
* @param inetSocketAddress the ip address of the client pinging the server
* @return string of the MOTD
* @return the ping information
*/
@Nullable
GeyserPingInfo getPingInformation(InetSocketAddress inetSocketAddress);
Expand Down

0 comments on commit 677a56c

Please sign in to comment.