fix: also serialize matrix/index.js import in channel.ts
The parallel account startup was crashing because the dynamic import of ./matrix/index.js returned undefined when called concurrently. Added importMatrixIndex() to import-mutex.ts and use it in channel.ts to ensure the module is only imported once during parallel startup.
This commit is contained in:
parent
c0e38bb990
commit
91f9010237
2 changed files with 21 additions and 1 deletions
|
|
@ -21,6 +21,7 @@ import {
|
|||
type ResolvedMatrixAccount,
|
||||
} from "./matrix/accounts.js";
|
||||
import { resolveMatrixAuth } from "./matrix/client.js";
|
||||
import { importMatrixIndex } from "./matrix/import-mutex.js";
|
||||
import { normalizeAllowListLower } from "./matrix/monitor/allowlist.js";
|
||||
import { probeMatrix } from "./matrix/probe.js";
|
||||
import { sendMessageMatrix } from "./matrix/send.js";
|
||||
|
|
@ -403,7 +404,8 @@ export const matrixPlugin: ChannelPlugin<ResolvedMatrixAccount> = {
|
|||
`[${account.accountId}] starting provider (${account.homeserver ?? "matrix"})`,
|
||||
);
|
||||
// Lazy import: the monitor pulls the reply pipeline; avoid ESM init cycles.
|
||||
const { monitorMatrixProvider } = await import("./matrix/index.js");
|
||||
// Use serialized import to prevent race conditions during parallel account startup.
|
||||
const { monitorMatrixProvider } = await importMatrixIndex();
|
||||
return monitorMatrixProvider({
|
||||
runtime: ctx.runtime,
|
||||
abortSignal: ctx.abortSignal,
|
||||
|
|
|
|||
|
|
@ -68,3 +68,21 @@ export async function importCredentials(): Promise<typeof import("./credentials.
|
|||
credentialsModule = mod;
|
||||
return mod;
|
||||
}
|
||||
|
||||
// Pre-cached import for matrix index module
|
||||
let matrixIndexModule: typeof import("./index.js") | null = null;
|
||||
|
||||
/**
|
||||
* Safely import the matrix/index.js module.
|
||||
* This is called from channel.ts during parallel account startup.
|
||||
*/
|
||||
export async function importMatrixIndex(): Promise<typeof import("./index.js")> {
|
||||
if (matrixIndexModule) return matrixIndexModule;
|
||||
|
||||
const mod = await serializedImport(
|
||||
"./matrix/index.js",
|
||||
() => import("./index.js")
|
||||
);
|
||||
matrixIndexModule = mod;
|
||||
return mod;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue