Attach/Dettach inconsistencies
LemADEC opened this issue ยท 9 comments
Useful information to include:
- Minecraft version 1.12.2
- CC: Tweaked version 1.80pr1.13
- notable other mods: Computronics-1.12.1-1.6.5
I've noticed several issues with Attach and Detach being called in weird ways:
1- on our server with large modpack, I see the same block being attached to the same peripheral many times per second, while both a chunkloaded. It feels like the chunk is reloaded without being unloaded since the detach call is hardly ever made.
2- in my dev space, SMP, the server crashed telling that a computer was already detached when detach() was actually never called. Logs are here: https://gist.github.com/LemADEC/c2b26e1e362733bd3178306ae5d56e6e
Related source code is here: https://gist.github.com/LemADEC/c689432faf5a881fae08ef342a6b472e
I'm having a hard time to reproduce this issue in SSP, I'm not sure why.
Computronics might be part of the issue, still investigating.
I'm storing the IComputerAccess (PeripheralWrapper) in an hashmap. I'm wondering if its hashcode remains stable over time, as that could explain some of the issues here.
I had a look at doing this for 1.104.0, but thinking about this again I'm not sure it's worth it. We now (mostly) use capabilities for registering peripherals, so this should be much less common.
This may be an issue with Computronic's multi-peripheral system (see Vexatos/Computronics@3c3a2a8). It might be worth trying with a more recent version of Computronics and seeing if it helps at all.
Without Computronics, just CC-Tweaked and my mod, I see weird stuff already: https://gist.github.com/LemADEC/baef1e88f721d05b4ec4bc273b59ed4e
This tends to confirm the hashcode is not stable over time:
[23:23:41] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore '2' @ world (-57 88 257) Disconnected Attaching to dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@5ab5f08b
...
[23:24:00] [ComputerCraft-Computer-Runner-0/ERROR] [warpdrive]: TileEntityShipCore '2' @ world (-57 88 257) Connected Already detached from dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@5ab5f08b 2 bottom, ignoring...
We don't override the hashCode
or equals
methods for anything on the PeripheralWrapper
hierarchy, so this is very weird. I'll have a prod on my local environment - monitors do something similar, so I'd suspect a similar bug exposes itself on their side.
I'm unable to reproduce with monitors in my dev-environment, which is very curious.
@LemADEC Can you print out the contents of CC_connectedComputers
in those messages too? I'm very curious as to see what they look like - it doesn't seem that computers are being detached twice here, more that the connected computer map is being very weird.
The Connected/Disconnected in the log tells us if the CC_connectedComputers
map is empty or not.
I've forgot to update the contains() to containsKey() when I've changed from a Set to Map, that's why it thinks the computer is already detached...
Removing Computronics from the server does fix the repeated attachments:
with Computronics-1.12.2-1.6.6.191-charset-wires
[14:23:34] [Thread-85/INFO] [THAUMCRAFT]: Starting aura thread for dim -101
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: java.lang.RuntimeException:
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at cr0s.warpdrive.block.TileEntityAbstractInterfaced.attach(TileEntityAbstractInterfaced.java:456)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.api.multiperipheral.WrappedMultiPeripheral.attach(WrappedMultiPeripheral.java:43)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.cc.multiperipheral.MultiPeripheral.attach(MultiPeripheral.java:98)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper.attach(PeripheralAPI.java:86)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI.startup(PeripheralAPI.java:346)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.initLua(Computer.java:739)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.access$1400(Computer.java:33)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer$1.execute(Computer.java:847)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.ComputerThread$TaskRunner.run(ComputerThread.java:284)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at java.lang.Thread.run(Thread.java:748)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Disconnected Attaching to dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@680d3e06 16 right
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/common to /warpdrive as /warpdrive
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/warpdriveShipCore to /warpdrive/ShipCore as /warpdrive/ShipCore
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/warpdriveShipCore/startup to /startup as /startup
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: java.lang.RuntimeException:
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at cr0s.warpdrive.block.TileEntityAbstractInterfaced.attach(TileEntityAbstractInterfaced.java:456)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.api.multiperipheral.WrappedMultiPeripheral.attach(WrappedMultiPeripheral.java:43)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.cc.multiperipheral.MultiPeripheral.attach(MultiPeripheral.java:98)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper.attach(PeripheralAPI.java:86)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI.startup(PeripheralAPI.java:346)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.initLua(Computer.java:739)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.access$1400(Computer.java:33)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer$1.execute(Computer.java:847)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.ComputerThread$TaskRunner.run(ComputerThread.java:284)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at java.lang.Thread.run(Thread.java:748)
[14:23:34] [ComputerCraft-Computer-Runner-0/ERROR] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Already attached to dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@680d3e06 16 right, ignoring...
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: java.lang.RuntimeException:
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at cr0s.warpdrive.block.TileEntityAbstractInterfaced.attach(TileEntityAbstractInterfaced.java:456)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.api.multiperipheral.WrappedMultiPeripheral.attach(WrappedMultiPeripheral.java:43)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.cc.multiperipheral.MultiPeripheral.attach(MultiPeripheral.java:98)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper.attach(PeripheralAPI.java:86)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI.startup(PeripheralAPI.java:346)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.initLua(Computer.java:739)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.access$1400(Computer.java:33)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer$1.execute(Computer.java:847)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.ComputerThread$TaskRunner.run(ComputerThread.java:284)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at java.lang.Thread.run(Thread.java:748)
[14:23:34] [ComputerCraft-Computer-Runner-0/ERROR] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Already attached to dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@680d3e06 16 right, ignoring...
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: java.lang.RuntimeException:
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at cr0s.warpdrive.block.TileEntityAbstractInterfaced.attach(TileEntityAbstractInterfaced.java:456)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.api.multiperipheral.WrappedMultiPeripheral.attach(WrappedMultiPeripheral.java:43)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at pl.asie.computronics.cc.multiperipheral.MultiPeripheral.attach(MultiPeripheral.java:98)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper.attach(PeripheralAPI.java:86)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI.startup(PeripheralAPI.java:346)
[14:23:34] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.initLua(Computer.java:739)
...
without Computronics
[14:41:15] [Thread-69/INFO] [THAUMCRAFT]: Starting aura thread for dim -101
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: java.lang.RuntimeException:
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at cr0s.warpdrive.block.TileEntityAbstractInterfaced.attach(TileEntityAbstractInterfaced.java:456)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper.attach(PeripheralAPI.java:86)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.apis.PeripheralAPI.startup(PeripheralAPI.java:346)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.initLua(Computer.java:739)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer.access$1400(Computer.java:33)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.Computer$1.execute(Computer.java:847)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at dan200.computercraft.core.computer.ComputerThread$TaskRunner.run(ComputerThread.java:284)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [STDERR]: [cr0s.warpdrive.block.TileEntityAbstractInterfaced:attach:456]: at java.lang.Thread.run(Thread.java:748)
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Disconnected Attaching to dan200.computercraft.core.apis.PeripheralAPI$PeripheralWrapper@419e3dba 16 right
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/common to /warpdrive as /warpdrive
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/warpdriveShipCore to /warpdrive/ShipCore as /warpdrive/ShipCore
[14:41:16] [ComputerCraft-Computer-Runner-0/INFO] [warpdrive]: TileEntityShipCore 'Lemian' @ solarSystem (-40547 58 28465) Connected Mounted lua.ComputerCraft/warpdriveShipCore/startup to /startup as /startup
[14:41:17] [ComputerCraft-Coroutine-2/INFO] [warpdrive]: [CC] LUA call from 16:right @ solarSystem (-40547 58 28465) to warpdriveShipCore.isInterfaced()
@LemADEC, have you made any progress on this issue? I'm fairly sure it's not in CC:T's end, but also don't want to close prematurely.
There is multiple scopes to consider here:
A- several mods are assuming the IPeripheralProvider is only called for a specific mod or block when in fact it's called for all blocks. On one end, this makes the API more flexible (allowing mod X to add CC support to mod Y); however, bad implementations are impacting CPU load silently.
In the case of WarpDrive, I was handling blocks from other mods when I should only handle mines.
In the case of PneumaticCraft, an handler was registered for every block in that mod, and every handler was handling all blocks, including from other mods.
I've found other mods with similar issues, but can't remember there names. PneumaticCraft was the biggest contributor by far. I'm waiting for it to be updated on Curse to confirm everything is fixed.
B- Computronics is changing the way peripheral handling is done from CC. I've yet to understand the benefit from this design. So right now, it feels like "reinventing the wheel" and adding more issues.
We did see TPS impacts from adding Computronics on our previous 1.7.10 modpacks without really understanding it back then. I guess it goes deeper than we suspected initially, so that mod has been removed from our current projects, sadly.
C- Regarding CC, given IPeripheralProvider implementation bugs are seen in multiple mods and fairly impacting, I advise to find a way to catch those errors without going through a specific code review. For example, we could add warnings in the logs:
1- systematically warn when the same mod is registering multiple handlers.
2- optionally warn when multiple handlers are accepting the same block.
3- warn when an handler is accepting blocks from other mods, and it's not 'whitelisted/known' to do so.
Adding a warning to the API documentation might help too.