I've been having an extended WTF moment lasting all weekend. I'd like somebody to either confirm that I need to do some more defensive coding, or reassure me that I'm hallucinating because of the nasty weather
this week. At the risk of bringing down the wrath of Phanx :-) I'm going to summarize; the relevant parts of the addon run about 5600 lines of code written in a style best described as "oh God why?"
The addon responds to a local client event (one of the CHAT_MSG_* family), and then also broadcasts a single string to other users of the same addon. Copies of the addon running for players out of range of the initial CHAT_MSG event will still react the same way, once they receive the broadcast. The event happens rarely, so we're not talking about a constant stream of data.
Both code paths (local chat event and receiving remote message) eventually go through the same routine:
function do_work (stuff)
..... more code containing debug_log calls .....
It's one of the older parts of this addon, working more-or-less smoothly for a couple of years. The routine named here as "debug_log" prints stuff to chat or to a tekDebug window, and additionally stores all lines into a SavedVariables table for postmortem analysis. Writing to the savedvar is strictly appending to the table.
The other night, the addon flagged a "this ought not to ever happen" condition. The debug log contained
BEGIN (local event)
<start of normal do_work output>
BEGIN (received message)
<error melon melon melon out of cheese>
<confused remnants of do_work output>
I've never had anything overlap like that before. I didn't even think it was a possibility; ever since first fooling with addons, I've been under the impression that the client fires events into the scripting engine one at a time, waiting until an event handler finishes before firing the next one. Possibly that was naive but it fit the available data and I don't have much experience with these sorts of things.
None of the relevant code is firing off timers or other things that simulate "waiting". There's no user interaction. Until Thursday I would have sworn on the grave of my mother[+] that both of the event handlers ran without interruption to completion. Correct behavior of the addon depends on it, in fact.
Bad assumption on my part? I'd hate to think we need to gate our control flow with a homegrown poor man's mutex. If it was a safe assumption, then... what just happened?
it's like molten core, but with stranglethorn vale humidity
[+] she's actually alive and in good health. hi mom!