Repository navigation
Clean up gateway lifecycle processes - #304
brookerslyn wants to merge 2 commits into
Conversation
|
I get what you're trying to solve here but this is pretty clearly heavily AI assisted, the defensive programming gives it away. There are three overlapping mechanisms for each problem: link + monitor + trap_exit in DiscordBot, and cleanup in The issues are real but manually managing process lifetimes from callbacks with The one valid thing here is that the intentional close paths (op reconnect / invalid session / stale heartbeat) exit with Happy to look at a version that goes that direction. As-is I don't want lifecycle micromanagement merged back into the callbacks. |
|
regarding the AI-assisted part: no, this wasn't AI-written. i used the websocket client source and some docs on the web, but that's it. that said, the point about the lifecycle layering is fair. my last PR got left unmerged because the fix was too narrow, so i overcorrected here trying to make sure reconnect paths didn't leave anything behind. the leak/stale-process issue is what i was trying to address, but i can see why trap_exit + manual cleanup + extra monitoring is more lifecycle micromanagement than this codebase wants i guess i'll correct the pr and drop the callback level cleanup then, thanks for the feedback |
discordbot was starting the gateway with
start_linkand also monitoring it, which meant an abnormal gateway exit could kill the bot before the existing:DOWNhandler got a chance to restart/resume itfor example, if the discord websocket drops and the gateway exits with something like
{:remote, :closed}, the existing monitor/restart path could get skipped because discordbot was still linked to that processthis fix makes that path actually work by trapping exits and ignoring stale lifecycle messages from old gateway pids
it also cleans up the heartbeat/sequence tracker when the gateway closes, and makes heartbeat stop when its socket owner dies, so reconnects don't leave old heartbeat processes hanging around
tested locally with a small lifecycle repro to confirm old heartbeat processes no longer stay alive after gateway exit
forgot to add docs to the code so i had to make a separate commit for it, sorry dustin, no clean history