mirror of https://github.com/openclaw/openclaw.git
fix(mattermost): deactivate slash state before async cleanup to prevent race
Snapshot registered commands, then deactivate state immediately on abort. Prevents race where new monitor activates fresh state that gets wiped by the delayed .then() of the old monitor's cleanup promise.
This commit is contained in:
parent
5bbe16f2ce
commit
434dc0ffd5
|
|
@ -1134,13 +1134,16 @@ export async function monitorMattermostProvider(opts: MonitorMattermostOpts = {}
|
|||
// Clean up slash commands on shutdown
|
||||
if (slashEnabled) {
|
||||
const onAbortCleanup = () => {
|
||||
// Snapshot registered commands before deactivating state
|
||||
const commands = getSlashCommandState(account.accountId)?.registeredCommands ?? [];
|
||||
// Deactivate state immediately to prevent race with re-activation
|
||||
deactivateSlashCommands(account.accountId);
|
||||
// Then clean up remote registrations asynchronously
|
||||
void cleanupSlashCommands({
|
||||
client,
|
||||
commands: getSlashCommandState(account.accountId)?.registeredCommands ?? [],
|
||||
commands,
|
||||
log: (msg) => runtime.log?.(msg),
|
||||
})
|
||||
.then(() => deactivateSlashCommands(account.accountId))
|
||||
.catch((err) => runtime.error?.(`mattermost: slash cleanup failed: ${String(err)}`));
|
||||
}).catch((err) => runtime.error?.(`mattermost: slash cleanup failed: ${String(err)}`));
|
||||
};
|
||||
opts.abortSignal?.addEventListener("abort", onAbortCleanup, { once: true });
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue