← ritwiksharma.com
Work
Project Zomboid Build 42 · Engine and multiplayer

Engine work

Running a live Build 42 multiplayer server means some problems sit below the mods, in the engine itself. These are four I found, traced and fixed, with the logs, stack traces and code behind each one.

The same evidence as a 2-page PDF

Role
Solo
Where
State of Undead Purge, live B42 multiplayer
When
Oct to Nov 2026
Tools
Kahlua Lua, reading the 42.21 jar, thread dumps, own profiler

A profiler for every event handler, and the 83-second freeze it caught

What I built. 000_ZombitaProfiler.lua loads first and wraps every Lua event handler of every mod on the server, timing each by file and line. Each minute it logs the slowest handlers, and it logs straight away when a long stall ends.

What it caught. On 17 Oct 2026, with 22 players online, the server stopped ticking for 83 seconds. My freeze watchdog took a thread dump during the freeze, and the profiler named the exact handler the moment the game came back. Log excerpts are shortened to fit (paths and package names cut) and carry no player names.

14:34:32 dump ~/freeze_dumps/20261017-143431.txt (main: RUNNABLE at StringLib.lower(StringLib.java:717))
14:34:32 FROZEN online file 37 s old (last write 14:33:54 UTC), 22 online, f=81143 +0 in 30 s
14:35:31 freeze over (ticking again) after 83 s

[17-10-26 14:35:17.311] LOG  : Lua  f:81145 st:1,670,542,295> [ZProf] 107s | 102143 ms in handlers | players 22 |
  1) 100085 ms  OnClientCommand  B42Pantherv2:LootZoneStore.lua:335  x778 | 2) 193 ms  LoadGridsquare ...
Sources: freeze watchdog log, server DebugLog 14:33-14:36 UTC, thread dump 20261017-143431.

Main thread stack from the dump, top down: String.toLowerCase ← StringLib.lower ← Kahlua pcall ← Event.trigger ← LuaEventManager.triggerEvent (OnClientCommand) ← GameServer.receiveClientCommand ← GameServer.main.

Cause. An admin opened the Panther loot-balancer's Loot Zones page. Their client then sent GetLootZones 75 times in 102 seconds. Each request copied, summarised and sorted the whole catalogue of 4,583 zones, calling lower() on both names in every comparison, and that command was exempt from the mod's own rate limit. The same handler had stalled the server for 148.8 s on 14 Oct. I wrote a throttle for that command and sent the mod's author the logs, the line and the cause.

The Perf page on the Soup website: ticks a minute, what is loaded, the box's load, and a table of the top Lua handlers by file and line, with milliseconds and calls.
The profiler today, on the server's Perf page: the Lua handlers that cost the most time in the last minute, by file and line.

A vanilla Build 42 crash traced into the jar: chicken coops on chunk unload

The crash. Players were thrown back to the main menu, some seconds after joining, when a chunk with a coop unloaded:

NullPointerException ... IsoAnimal.removeFromUpdateLists() because "animal" is null
    at IsoHutch.removeFromWorld(IsoHutch.java:1095)

What the jar showed (42.21, read class by class). NetworkPlayerAI.parse(AnimalPacket) does animalInside.put(oldPos, null) and only refills the slot when the packet names a new one. So a hen leaving the coop leaves a null on the client. When the chunk unloads, IsoHutch.removeFromWorld walks that map and throws on the null.

A first fix that ran on OnTick never fired before the exception. The frame order explains why: GameClient.update (packets) runs, then OnTickEvenPaused, then ProcessChunkPos (the unload, where it throws), and only then OnTick. So the check now runs on OnTickEvenPaused, the only hook between the packet and the unload:

--- Rebuild one coop's animal list without empty slots. Returns how many empty slots were dropped (0 = untouched).
function HF.clean(hutch)
    local map = hutch:getAnimalInside()
    if not map or map:size() == 0 then return 0 end
    local list = ArrayList.new()
    list:addAll(map:values())
    local keep, empty = {}, 0
    for i = 0, list:size() - 1 do
        local a = list:get(i)
        if a == nil then empty = empty + 1 else keep[#keep + 1] = a end
    end
    if empty == 0 then return 0 end
    map:clear()
    for _, a in ipairs(keep) do pcall(function() hutch:addAnimalInside(a, false) end) end
    return empty
end
...
if Events and Events.OnTickEvenPaused then Events.OnTickEvenPaused.Add(HF.onFrame) end
From client/ZX_HutchFix.lua (372 lines, shipped in the live mod). Lua can't use the map's keys (Integer keys reach Lua as Double), so it rebuilds from values().

One string over 32 KB breaks on every client

Symptom. On 11 Oct 2026 the in-game leaderboard stuck on "Waiting for server..." for everyone, and every client logged NegativeArraySizeException.

Cause. Server-to-client commands write each text value with a 2-byte length, and the rankings JSON had just passed 37 KB as the player count grew. The fix sends big texts in pieces:

-- 1.7.173: the game sends each text value of a server command with a 2-byte length, so one string over ~32 KB
-- arrives broken ("NegativeArraySizeException" on every client, the board stuck on "Waiting for server..."). The
-- board passed 37 KB on 2026-10-11 as players grew. Big texts now go in pieces of PART_CHARS characters (p1..pn + n);
-- a small one still goes as data. Kahlua strings are Java strings, so sub() never splits a character, and 10,000
-- characters stay under the limit even if every one needs 3 bytes.
local PART_CHARS = 10000
local function lbArgs(text)
    text = tostring(text or "")
    if #text <= PART_CHARS then return { data = text } end
    local args, n, i = {}, 0, 1
    while i <= #text do
        n = n + 1
        args["p" .. n] = text:sub(i, i + PART_CHARS - 1)
        i = i + PART_CHARS
    end
    args.n = n
    return args
end
From server/ZombitaLeaderboardServer.lua. The client joins the parts back together.

Removing a mod from a live Build 42 save

Normally you can't take a mod off a running B42 server without breaking it. I found out why by reading the jar, then proved it on scratch dedicated servers on my own PC (31 Oct 2026):

This is how we removed a vaccine mod from the live server without a wipe.

The scratch-server logs from that test weren't kept. I can re-run it and show it live.

What this demonstrates

Related work