sbrl / Minetest-WorldEditAdditions

Extra tools and commands to extend WorldEdit for Minetest
https://worldeditadditions.mooncarrot.space/
Mozilla Public License 2.0
16 stars 3 forks source link

pos_marker_manage.lua:119: attempt to index a nil value #105

Open Bastrabun opened 10 months ago

Bastrabun commented 10 months ago

Happens when I place WE points via //1 and //2:

2023-11-10 20:23:51: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'worldeditadditions_core' in callback luaentity_Activate(): ...tions/worldeditadditions_core/core/pos_marker_manage.lua:119: attempt to index a nil value
2023-11-10 20:23:51: ERROR[Main]: stack traceback:
2023-11-10 20:23:51: ERROR[Main]: ...tions/worldeditadditions_core/core/pos_marker_manage.lua:119: in function 'next_func'
2023-11-10 20:23:51: ERROR[Main]: ...Additions/worldeditadditions_core/utils/EventEmitter.lua:69: in function 'emit'
2023-11-10 20:23:51: ERROR[Main]: ...ons/worldeditadditions_core/core/entities/pos_marker.lua:48: in function 'func'
2023-11-10 20:23:51: ERROR[Main]: ...inetest_test/bin/../builtin/profiler/instrumentation.lua:108: in function <...inetest_test/bin/../builtin/profiler/instrumentation.lua:101>

For my reference: 5381

sbrl commented 10 months ago

Hello there, @Bastrabun! I can't seem to replicate this issue myself.

Can you find the following information for me please?

Could you also try:

cheapie commented 4 months ago

I've been seeing this on occasion on another server as well, seems to happen about once a day and usually a few minutes after the last WE usage.

2024-05-10 20:20:47: ERROR[Main]: ServerError: AsyncErr: Lua: Runtime error from mod 'worldeditadditions_core' in callback luaentity_Activate(): ...tions/worldeditadditions_core/core/pos_marker_manage.lua:119: attempt to index a nil value
2024-05-10 20:20:47: ERROR[Main]: stack traceback:
2024-05-10 20:20:47: ERROR[Main]:   ...tions/worldeditadditions_core/core/pos_marker_manage.lua:119: in function 'next_func'
2024-05-10 20:20:47: ERROR[Main]:   ...Additions/worldeditadditions_core/utils/EventEmitter.lua:69: in function 'emit'
2024-05-10 20:20:47: ERROR[Main]:   ...ons/worldeditadditions_core/core/entities/pos_marker.lua:48: in function 'func'
2024-05-10 20:20:47: ERROR[Main]:   ...e/medic/mt58/bin/../builtin/profiler/instrumentation.lua:108: in function <...e/medic/mt58/bin/../builtin/profiler/instrumentation.lua:101>

This is with WE and WE additions both fully up to date (WE @ 5a00c07 and WE additions @ e89d610) as of this writing.

sbrl commented 1 month ago

Hmmmmmmmm, very interesting.

So that would suggest https://github.com/sbrl/Minetest-WorldEditAdditions/blob/e89d61034fcbf8f2ce9479efc6101155f13cee18/worldeditadditions_core/core/pos_marker_manage.lua#L119 is the root cause. Going by this I would hazard a guess that it's actually line 118 causing the issue here:

position_entities[event.player_name][event.i]

......so that would suggest a race condition between https://github.com/sbrl/Minetest-WorldEditAdditions/blob/d3ddb5575ea0ca6de83d083922bc342bb2d88203/worldeditadditions_core/core/entities/pos_marker.lua#L49-L55 emitting the update_entity function and pos_marker_manage's listener to the same event firing.

That shouldn't be possible though, because Lua is single-threaded, and our EventEmitter implementation doesn't use async code, therefore guaranteeing it calls the listeners in order immediately.

In 977dcc6 I have added some additional checks there. I've also added some logging that will log more information if the issue I suspect here happens again. If it does happen again, please do log the output because it will help me track the issue down.

We'll get to the bottom of this one eventually, @Bastrabun!