koraktor / steam-condenser

A multi-language library for querying the Steam Community, Source, GoldSrc servers and Steam master servers
https://koraktor.de/steam-condenser
Other
356 stars 67 forks source link

[Java] NullPointerException on GameServer.updatePlayers() with bots online #318

Closed sweepies closed 5 years ago

sweepies commented 6 years ago
java.lang.NullPointerException
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:549)
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:509)

output of status (edited):

qhostname: Development Server
version : 16.12.01/24 6835 secure
udp/ip  : xxx.xxx.xxx.xxx:27016  (public ip: xxx.xxx.xxx.xxx)
map     : rp_downtown_v4c_v2 at: 0 x, 0 y, 0 z
players : 3 (64 max)

# userid name                uniqueid            connected ping loss state  adr
#      2 "Bot01"             BOT                                     active
#      3 "Bot02"             BOT                                     active
#      4 "Bot03"             BOT                                     active
rcon from "xxx.xxx.xxx.xxx:34394": command "status"

The game is Garry's Mod if that makes a difference.

sweepies commented 6 years ago

Looks like there was a character entered in the rcon console which resulted in the letter q being present before hostname in the status output. Definitely a strange issue. Perhaps implement a protection against mangled output like this or throw a different exception? I'll leave this open for now.

sweepies commented 6 years ago

Another thing I just noticed, calling updatePlayers() many times within a short period of time will result in:

java.lang.ArrayIndexOutOfBoundsException
        at java.lang.System.arraycopy(Native Method)
        at com.github.koraktor.steamcondenser.steam.sockets.RCONSocket.getReply(RCONSocket.java:119)
        at com.github.koraktor.steamcondenser.steam.servers.SourceServer.rconExec(SourceServer.java:182)
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:539)
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:509)

and immediately memory usage skyrocketed from 40MiB to 3GiB subsequently resulting in:

        at java.nio.HeapByteBuffer.<init>(HeapByteBuffer.java:57)
        at java.nio.ByteBuffer.allocate(ByteBuffer.java:335)
        at com.github.koraktor.steamcondenser.steam.sockets.SteamSocket.receivePacket(SteamSocket.java:120)
        at com.github.koraktor.steamcondenser.steam.sockets.RCONSocket.getReply(RCONSocket.java:118)
        at com.github.koraktor.steamcondenser.steam.servers.SourceServer.rconExec(SourceServer.java:182)
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:539)
        at com.github.koraktor.steamcondenser.steam.servers.GameServer.updatePlayers(GameServer.java:509)

Memory usage remained at 1.72GiB after GC and the only way to fix this is to restart the process.

koraktor commented 6 years ago

Sorry for the late response. Does the original issue occur when no bots are on the server?

Can you provide a packet trace (e.g. using Wireshark or tcpdump) of the second issue (many requests in a short timeframe)?

koraktor commented 6 years ago

@sweepyoface: I can’t seem to reproduce this error (even when injecting your status output exactly). What exactly did you edit?

PS: Are you using threads for your quick requests? The socket code is not thread-safe.

sweepies commented 6 years ago

I'm trying to figure out the best way of diagnosing and providing more information about this issue, I'll have to redeploy it and look into this. This could very well be an issue with my code and needs a fresh read.

koraktor commented 6 years ago

@sweepyoface Any update on this?

sweepies commented 5 years ago

Completely forgot about this – I've deprecated that project having progressed a lot (making that code base look like a horrible mess), and I've mostly moved on from Java so will probably be rewriting it in Node.

This issue was likely my fault and I don't have plans to run that again, but thanks for the help.