minetest-mods / castle_gates

Large swinging and sliding gate components suitable for a castle
MIT License
9 stars 8 forks source link

gate_functions.lua:406: attempt to index a nil value #17

Closed Bastrabun closed 1 year ago

Bastrabun commented 3 years ago

Not sure what was attempted by the user.

2021-09-12 19:46:47: ERROR[Main]: ServerError: AsyncErr: environment_Step: Runtime error from mod '' in callback environment_Step(): ...e/mtlive1/.minetest/mods/castle_gates/gate_functions.lua:406: attempt to index a nil value
2021-09-12 19:46:47: ERROR[Main]: stack traceback:
2021-09-12 19:46:47: ERROR[Main]:   ...e/mtlive1/.minetest/mods/castle_gates/gate_functions.lua:406: in function 'func'
2021-09-12 19:46:47: ERROR[Main]:   ...ive1/5.4.1/Minetest_live/bin/../builtin/common/after.lua:26: in function 'func'
2021-09-12 19:46:47: ERROR[Main]:   ...inetest_live/bin/../builtin/profiler/instrumentation.lua:106: in function <...inetest_live/bin/../builtin/profiler/instrumentation.lua:100>
2021-09-12 19:46:47: ERROR[Main]:   ...ve1/5.4.1/Minetest_live/bin/../builtin/game/register.lua:422: in function <...ve1/5.4.1/Minetest_live/bin/../builtin/game/register.lua:406>
2021-09-12 19:46:47: ERROR[Main]: stack traceback: corrupted double-linked list

For my reference 897

Bastrabun commented 2 years ago

In issue #15 you kindly allowed

EDIT: Feel free to @ me when you find such errors if nobody seems to be active.

I feel like this is the case here again, so I do summon thee, @SmallJoker

Thank you very much

SmallJoker commented 2 years ago

@Bastrabun gate_functions.lua:406 does not point to any relevant code (checked 21b5a6c00, March 2021). Please provide a stack backtrace using an unmodified castle_gates version, or provide the failing line contents in case you absolutely need a modification in this file.

Bastrabun commented 2 years ago

This is the affected line: https://github.com/minetest-mods/castle_gates/blob/master/gate_functions.lua#L402 in fc78d92

which reads

castle_gates.trigger_gate(door.all[1].pos, door.all[1].node,

SmallJoker commented 2 years ago

Do you know of any reproduction steps? This seems to be related to hinges only, but I cannot figure out why door.all would be an empty table.

Bastrabun commented 2 years ago

Unfortunately not. I did not find the user who did it and I wasn't able to reproduce the crash. Also there were no "uncommon" constructions involving hinges to be found.

We have a testserver where we can make any kind of experiments and we can add logging to the mod per your suggestion.

So far, it only happened once, while the castle_gate blocks are used on a daily basis

SmallJoker commented 2 years ago

I suppose this would be the easiest way to find the culprit:

minetest.after(1, function(player_name)
    if not door.all[1] then
        minetest.log("warning", "HINGE ERROR WITH NODE " .. dump(node) .. ": " .. dump(door.all))
        return
    end
    -- Get current player ObjectRef (nil when gone)
    castle_gates.trigger_gate(door.all[1].pos, door.all[1].node,
        minetest.get_player_by_name(player_name))
end, player:get_player_name())
Bastrabun commented 2 years ago

Will add and then call a bug bounty on castle gate hinge crashes :D

S-S-X commented 1 year ago

Same thing just crashed another server, tried to ask for steps to reproduce but not sure if I get anything. Attempt to index nil @ castle_gates.trigger_gate(door.all[1].pos, door.all[1].node, (gate_functions.lua:441).

S-S-X commented 1 year ago

seems like using an already moving castle_gates:steel_portcullis_bars caused this one.

Didn't try and didn't read code that carefully but makes sense if it causes "double trigger" for trigger_gate function and leaves door.all empty (which also seems very much possible).

FeXoR-o-Illuria commented 1 year ago

Yes, using (right-clicking/placing) a gate node while the gate is already moving can trigger the crash. Rapidly clicking a gate segment that has multiple voxels to move triggers it reliably.

Niklp09 commented 1 year ago

@Bastrabun should be fixed now

S-S-X commented 1 year ago

@Bastrabun should be fixed now

I guess this almost sure also fixes case where gate is activated rapidly multiple times presumably caused by before core.after(1, xyz) had chance to actually run resulting in multiple consecutive jobs for same pos.

I guess multiple jobs can still be queued? But it just wont finish those anymore.

I mean issue that was temporarily fixed on pandorabox by switching to https://github.com/S-S-X/castle_gates/commit/818a204b9f38048b5099c45b23c495f3cb3efc29 because it was already more like public server restart button than rare bug crashing server.

edit. I mean Lua error, not crashing server but raising an error that removes server from existence.

Bastrabun commented 1 year ago

Do you have a surefire repro so I could test with and without the fix?

Niklp09 commented 1 year ago

Fixed in https://github.com/minetest-mods/castle_gates/commit/c4316a082159d6a4977faaab1bf2cb38d854c97d (cannot reproduced anymore)