Stop hanging if appservice crashes at startup.

Fixes https://github.com/the-draupnir-project/Draupnir/issues/503.
This commit is contained in:
gnuxie
2025-01-15 21:42:31 +00:00
parent c3552d0c59
commit f03e2f3f7f
2 changed files with 17 additions and 20 deletions
+16 -10
View File
@@ -225,16 +225,22 @@ export class MjolnirAppService {
): Promise<MjolnirAppService> {
Logger.configure(config.logging ?? { console: "debug" });
const dataStore = new PgDataStore(config.db.connectionString);
await dataStore.init();
const service = await MjolnirAppService.makeMjolnirAppService(
config,
dataStore,
DefaultEventDecoder,
registrationFilePath
);
// The call to `start` MUST happen last. As it needs the datastore, and the mjolnir manager to be initialized before it can process events from the homeserver.
await service.start(port);
return service;
try {
await dataStore.init();
const service = await MjolnirAppService.makeMjolnirAppService(
config,
dataStore,
DefaultEventDecoder,
registrationFilePath
);
// The call to `start` MUST happen last. As it needs the datastore, and the mjolnir manager to be initialized before it can process events from the homeserver.
await service.start(port);
return service;
} catch (e: unknown) {
log.error("Failed to start the appservice", e);
await dataStore.close();
throw e;
}
}
public onUserQuery(_queriedUser: MatrixUser) {
+1 -10
View File
@@ -11,7 +11,6 @@
import { Cli } from "matrix-appservice-bridge";
import { MjolnirAppService } from "./AppService";
import { IConfig } from "./config/config";
import { Task } from "matrix-protection-suite";
/**
* This file provides the entrypoint for the appservice mode for draupnir.
@@ -31,15 +30,7 @@ const cli = new Cli({
if (config === null) {
throw new Error("Couldn't load config");
}
void Task(
(async () => {
await MjolnirAppService.run(
port,
config,
cli.getRegistrationFilePath()
);
})()
);
void MjolnirAppService.run(port, config, cli.getRegistrationFilePath());
},
});