CC: Tweaked

CC: Tweaked

57M Downloads

VarargArguments is not thread safe

SquidDev opened this issue ยท 0 comments

commented

Minecraft Version

1.16.x

Version

1.103.0

Details

If a VarargArguments is shared between threads (for instance, if a peripheral method runs on the main thread), then IArguments.get will be evaluated on the main thread. As a result, tables will be iterated over on the incorrect thread, possibly leading to race conditions and/or unexpected errors:

return cache[index] = CobaltLuaMachine.toObject(varargs.arg(index + 1), null);

We solved this in the Waluaigi branch by adding an IArguments.escapes method, which is called inside the mainThread wrappers. This then takes a defensive copy of the given arguments.

If we implement #1355, we'll also need to take a defensive copy of the type names, but I'd expect that to be relatively cheap - we probably only need to do this if we ever have a custom name after all!