SirEdvin / UnlimitedPeripheralWorks

Extreme compact CC:R and CC:T mod that tries to make everything, that even possible a peripheral
MIT License
8 stars 3 forks source link

Randomly peripherals or storage unable to be found #19

Closed Linguardium closed 11 months ago

Linguardium commented 11 months ago

[✔] peripheralium-0.4.21-1.19.2 [✔] peripheralworks-0.2.8

(AOF6 1.7.1)

Stading next to the network using wired modems, occasionally receive errors saying it could not connect to a peripheral. log shows error:

[21:39:36] [Server thread/ERROR]: Error running task
dan200.computercraft.api.peripheral.NotAttachedException: You are not attached to this computer
    at dan200.computercraft.shared.peripheral.modem.wired.WiredModemPeripheral$RemotePeripheralWrapper.getAvailablePeripheral(WiredModemPeripheral.java:496) ~[cc-restitched-1.101.2.jar:?]
    at site.siredvin.peripheralium.extra.plugins.AbstractInventoryPlugin.pushItems(AbstractInventoryPlugin.kt:58) ~[peripheralium-0.4.21-1.19.2.jar:?]
    at site.siredvin.peripheralium.extra.plugins.AbstractInventoryPlugin$cc$pushItems4.apply(CC generated method) ~[?:?]
    at dan200.computercraft.core.asm.PeripheralMethod.lambda$static$0(PeripheralMethod.java:21) ~[cc-restitched-1.101.2.jar:?]
    at dan200.computercraft.core.lua.LuaContext.lambda$issueMainThreadTask$0(LuaContext.java:34) ~[cc-restitched-1.101.2.jar:?]
    at dan200.computercraft.core.computer.MainThreadExecutor.execute(MainThreadExecutor.java:143) ~[cc-restitched-1.101.2.jar:?]
    at dan200.computercraft.core.computer.MainThread.executePendingTasks(MainThread.java:157) ~[cc-restitched-1.101.2.jar:?]
    at dan200.computercraft.shared.proxy.ComputerCraftProxyCommon.lambda$registerHandlers$3(ComputerCraftProxyCommon.java:105) ~[cc-restitched-1.101.2.jar:?]
    at net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents.lambda$static$0(ServerTickEvents.java:40) ~[fabric-lifecycle-events-v1-2.2.4+1b46dc7890-db0fd3f5dc0d6099.jar:?]
    at net.minecraft.server.MinecraftServer.handler$ejc000$fabric-lifecycle-events-v1$onStartTick(MinecraftServer.java:7316) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_3748(MinecraftServer.java:819) ~[client-intermediary.jar:?]
    at net.minecraft.class_1132.method_3748(class_1132.java:98) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_29741(MinecraftServer.java:665) ~[client-intermediary.jar:?]
    at net.minecraft.server.MinecraftServer.method_29739(MinecraftServer.java:257) ~[client-intermediary.jar:?]
    at java.lang.Thread.run(Thread.java:833) [?:?]
SirEdvin commented 11 months ago

So, I will take a look today, but if you have time, can you provide a screenshot of your setup or answer to following question:

Linguardium commented 11 months ago

Aof6 1.7.1 for modlist. The network spanned a chunk barrier but i was standing in one of the 2 facing the other. All chunks stayed loaded. I was passing around wrapped peripherals rather than doing storing the name and using a name lookup each time. Only wired modems with the 1 computer. I did have issues when multiple inventories were connected to a full block modem and there was still one of those in the setup. The rest were panels.

Unfortunately pack just updated with breaking changes and I wiped the instance with the setup.

The storage worked fine normally but randomly gave not connected errors. Restarting the script worked fine again

Linguardium commented 11 months ago

More information: I seem to only run into this issue when using parallel. I built some new code on the new version and everything worked fine until I used parallel to run functions. While i dont have a minimum reproducible code, everything is looked up by peripheral name this time using global static variables and peripheral.call.

SirEdvin commented 11 months ago

So, you just using several (like 6 or less) inventory peripheral in paraller and this occurs time to time?

Linguardium commented 11 months ago

items are moved in phases, from inventory 1 to inventory 2, then pause 1 second and check if inventory 2 is done with it, if so, move to inventory 3, etc

during pauses, inventories are checked for counts and and update messages are sent to a monitor.

occasionally, when attempting to move the item, it will fail and say the peripheral is not connected (though when this happened i had some printouts specifically getting the peripheral information from the network, so it was clearly attached)

it still does happen without parallel (coroutine library in cc) but is significantly more frequent when using it. definitely feels like a race condition of some sort.

the system as a whole is only moving 1 item through it at a time, so there is never a blocking situation in any target inventory

Linguardium commented 11 months ago

did some more testing...

when listening to the attached and detached events, i notice that certain peripheral modems are being detached and attached (these correspond to the error occurs). I am wondering if this has to do with block entities updating states on blocks (replacing the blockstate with the new one with the new property)

I will do some more testing but with the current testing it appears that when a block entity updates a blockstate, it causes a detach and refresh event. I am not certain, but I would assume that if item movement calls are being made after the invalidation but before the refresh, it would give a "not attached" message.

I have tested this with a modem attached to a barrel and a lua script listening for detach events. when i open the barrel (and thus the state changes to show it is being looked at), it fires the detach event

SirEdvin commented 11 months ago

So, this is common CC:T (or CC:T) behavior, because any block update around computer/model causes peripheral re-connection (like here). This behavior is by design and unfortunately, there is nothing to fix here.

The real question, I suppose, do this happens only when block state changes or there is some heisenbug in UPW that causes it to happens also ....

Linguardium commented 11 months ago

Yeah, i will test only CC:T and see if the problem can be replicated there alone, now that i have some test cases. thanks for bearing with me

Linguardium commented 11 months ago

Ok, is reproducible and is caused by UPW Test setup:

3 barrels with modems attached. 1 computer with modem attached. cables connected to all

put an item in one of the barrels write a script loop to cycle the item from barrel1 to 2, wait, then 2 to 3 then back while script is running, open a barrel a few times in succession

I tested with just CC:T, with CC:T+Peripheralium only, and with CC:T+UPW

If "Enable Generic Inventory" is enabled, you can crash the program by opening the barrel. if not, it doesnt crash.

crashlog: https://snippet.host/gzyrpg

SirEdvin commented 11 months ago

So, I build a reproducible environment, however, I requested help about this issue, because I have literally zero idea why this happening.

It is seems that modem (?) is not connected anymore or something like this, which is very strange ... I will try to debug, but I am not sure, that I will have something

SirEdvin commented 11 months ago

So, you can try new peripheralium and UPW, that released today, this should be fixed.

Issue is not closed, because this problem also need to be fixed in 1.19.4 and 1.20.1

Linguardium commented 11 months ago

Seems to be resolved. Thanks for all the effort :)

SirEdvin commented 11 months ago

Thank you for helping solving this out!

Update for all versions, except 1.19.4 (let is just die)