GTNewHorizons / GT-New-Horizons-Modpack

New Modpack with Gregtech, Thaumcraft and Witchery
https://www.gtnewhorizons.com/
Other
891 stars 280 forks source link

Drone Centre Memory Leak #16005

Closed norbby42 closed 2 months ago

norbby42 commented 2 months ago

Your GTNH Discord Username

Quackers#6418

Your Pack Version

2.6.0-beta2

Your Server

Private Dedicated

Java Version

Java 17

Type of Server

Vanilla Forge

Your Expectation

Drone DownLinks would properly switch from 1 Drone Centre to another when the active centre is destroyed.

The Reality

  1. Construct a Drone Centre and insert a Tier 3 Drone
  2. Place several Drone Uplink Hatches on multiblocks and confirm they link to the Drone Centre
  3. Build a 2nd Drone Centre within range of the 1st Drone Centre (< 512 blocks) and insert a Tier 3 Drone
  4. Place several new Drone Uplink Hatches on multiblocks until they start linking to the 2nd Drone Centre
  5. Using a Vajra, destroy the 2nd Drone Centre in its entirety
  6. Go to the 1st Drone Centre and observe that its connection count in WAILA is rising steadily and quickly goes above the actual number of connected machines
  7. Attempting to view the connected machines may cause you to be disconnected after a certain point, presumably due to the list becoming too long

Your Proposal

There's a bug of some kind, good luck!

Final Checklist

norbby42 commented 2 months ago

I just noticed that GT_MetaTileEntity_Hatch_DroneDownLink#tryFindConnection does not break on registering with the first found drone centre. If there are 5 centres in range, it will establish a connection with all 5 (but not retain 1-4 locally).

https://github.com/GTNewHorizons/GT5-Unofficial/blob/b9aaf5b191bd2b00cd3ca8079d962178dc1d2985/src/main/java/gregtech/common/tileentities/machines/multi/drone/GT_MetaTileEntity_Hatch_DroneDownLink.java#L193


Observation 2:

In GT_MetaTileEntity_Hatch_DroneDownLink#onPostTick, it calls HasConnection() to validate the connection to the Drone Centre, then if it fails every 10 seconds it nulls out its reference to the DroneConnection object and calls tryFindConnection to try to find a new one.

I'm betting that null'ing out the connection is what's allowing connections to stack up in Drone Centres - it doesn't remove the connection from its associated Drone Centre's connectionList.


This is all guesswork from reading GitHub. Sadly I'm not going to be in an environment where I could actually debug this for some time.

HoleFish commented 2 months ago

@RealSilverMoon