File tree Expand file tree Collapse file tree 5 files changed +22
-6
lines changed Expand file tree Collapse file tree 5 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -48,6 +48,7 @@ import { ResultError } from "@gnuxie/typescript-result";
4848import { SafeModeCause , SafeModeReason } from "./safemode/SafeModeCause" ;
4949import { SafeModeBootOption } from "./safemode/BootOption" ;
5050import { TopLevelStores } from "./backingstore/DraupnirStores" ;
51+ import { patchMatrixClient } from "./utils" ;
5152
5253const log = new Logger ( "DraupnirBotMode" ) ;
5354
@@ -111,6 +112,7 @@ export class DraupnirBotModeToggle implements BotModeTogle {
111112 config : IConfig ,
112113 stores : TopLevelStores
113114 ) : Promise < DraupnirBotModeToggle > {
115+ patchMatrixClient ( ) ;
114116 const clientUserID = await client . getUserId ( ) ;
115117 if ( ! isStringUserID ( clientUserID ) ) {
116118 throw new TypeError ( `${ clientUserID } is not a valid mxid` ) ;
Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ import {
4949} from "@the-draupnir-project/matrix-basic-types" ;
5050import { SqliteRoomStateBackingStore } from "../backingstore/better-sqlite3/SqliteRoomStateBackingStore" ;
5151import { TopLevelStores } from "../backingstore/DraupnirStores" ;
52+ import { patchMatrixClient } from "../utils" ;
5253
5354const log = new Logger ( "AppService" ) ;
5455/**
@@ -230,6 +231,7 @@ export class MjolnirAppService {
230231 registrationFilePath : string
231232 ) : Promise < MjolnirAppService > {
232233 Logger . configure ( config . logging ?? { console : "debug" } ) ;
234+ patchMatrixClient ( ) ;
233235 const dataStore = new PgDataStore ( config . db . connectionString ) ;
234236 await dataStore . init ( ) ;
235237 const eventDecoder = DefaultEventDecoder ;
Original file line number Diff line number Diff line change @@ -321,6 +321,19 @@ function getConfigMeta(): NonNullable<IConfig["configMeta"]> {
321321 } ;
322322}
323323
324+ let configHookExitDump : undefined | ( ( ) => void ) = undefined ;
325+
326+ function registerConfigExitHook ( config : IConfig ) : void {
327+ if ( configHookExitDump ) {
328+ return ;
329+ }
330+ configHookExitDump = ( ) => {
331+ logNonDefaultConfiguration ( config ) ;
332+ logConfigMeta ( config ) ;
333+ } ;
334+ process . on ( "exit" , configHookExitDump ) ;
335+ }
336+
324337/**
325338 * @returns The users's raw config, deep copied over the `defaultConfig`.
326339 */
@@ -349,10 +362,7 @@ function readConfigSource(): IConfig {
349362 unknownProperties
350363 ) ;
351364 }
352- process . on ( "exit" , ( ) => {
353- logNonDefaultConfiguration ( config ) ;
354- logConfigMeta ( config ) ;
355- } ) ;
365+ registerConfigExitHook ( config ) ;
356366 return config ;
357367}
358368
Original file line number Diff line number Diff line change @@ -20,7 +20,7 @@ import {
2020} from "matrix-bot-sdk" ;
2121import { StoreType } from "@matrix-org/matrix-sdk-crypto-nodejs" ;
2222import { configRead as configRead , getStoragePath } from "./config" ;
23- import { initializeSentry , patchMatrixClient } from "./utils" ;
23+ import { initializeSentry } from "./utils" ;
2424import { DraupnirBotModeToggle } from "./DraupnirBotMode" ;
2525import { SafeMatrixEmitterWrapper } from "matrix-protection-suite-for-matrix-bot-sdk" ;
2626import { DefaultEventDecoder } from "matrix-protection-suite" ;
@@ -81,7 +81,6 @@ void (async function () {
8181 storage
8282 ) ;
8383 }
84- patchMatrixClient ( ) ;
8584 const eventDecoder = DefaultEventDecoder ;
8685 const stores = makeTopLevelStores ( storagePath , eventDecoder , {
8786 isRoomStateBackingStoreEnabled :
Original file line number Diff line number Diff line change @@ -60,6 +60,7 @@ async function cleanUpTopLevelStores(storagePath: string) {
6060 }
6161 } )
6262 ) ;
63+ //
6364}
6465
6566// When Draupnir starts (src/index.ts) it clobbers the config by resolving the management room
@@ -106,6 +107,8 @@ export const mochaHooks = {
106107 await this . toggle ?. stopEverything ( ) ;
107108 draupnirClient ( ) ?. stop ( ) ;
108109 this . stores ?. dispose ( ) ;
110+ // With regret, please see https://github.com/the-draupnir-project/Draupnir/issues/927.
111+ await new Promise ( ( resolve ) => setTimeout ( resolve , 50 ) ) ;
109112 if ( this . draupnir !== undefined ) {
110113 await Promise . all ( [
111114 this . draupnir . client . setAccountData (
You can’t perform that action at this time.
0 commit comments