From 7a148f8caacbaf3b8370445a49a26e33e4fda24f Mon Sep 17 00:00:00 2001 From: javis-bot Date: Wed, 10 Jun 2026 12:10:01 +0900 Subject: [PATCH] fix: don't unlock active in startup catch when a newer attempt owns it The startup catch cleared this.active unconditionally. In a stop()+restart race during the slow login/pauses, the first attempt's catch would fire after the second start() had already taken the lock, unlocking it mid-startup and letting a third start() race in. Guard the active/state reset with `this.controller === controller`, matching the field-null and playStream .finally guards. Verified live: stop during login then restart keeps the restart's lock (active stays true), and it clears to false only once truly stopped; no crash. --- bot/src/stream/selfbot.ts | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/bot/src/stream/selfbot.ts b/bot/src/stream/selfbot.ts index 1b53749..48b2cf2 100644 --- a/bot/src/stream/selfbot.ts +++ b/bot/src/stream/selfbot.ts @@ -197,10 +197,16 @@ export class SelfbotStreamer implements ScreenStreamer { } catch { /* ignore */ } - if (this.capture === capture) this.capture = null; - if (this.streamer === streamer) this.streamer = null; - if (this.controller === controller) this.controller = null; - this.active = false; + // Only release the lock / clear instance state if WE are still the + // current attempt. If a concurrent stop()+start() already replaced the + // controller, a newer start() owns `active` — clearing it here would + // unlock it mid-startup and let a third start() race in. + if (this.controller === controller) { + if (this.capture === capture) this.capture = null; + if (this.streamer === streamer) this.streamer = null; + this.controller = null; + this.active = false; + } if (signal.aborted) return "송출을 시작하는 중에 중지했습니다."; throw e; }