Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash at startup on dendrite with empty mjolnir state #443

Closed
bones-was-here opened this issue Dec 4, 2022 · 9 comments
Closed

Crash at startup on dendrite with empty mjolnir state #443

bones-was-here opened this issue Dec 4, 2022 · 9 comments

Comments

@bones-was-here
Copy link

After having tried to run mjolnir previously #305 I set all of the following state events to have empty content {} to get a "fresh start": org.matrix.mjolnir.protected_rooms org.matrix.mjolnir.enabled_protections org.matrix.mjolnir.watched_lists org.matrix.mjolnir.default_list

The homeserver is dendrite 0.10.8

The result is

Thu, 01 Dec 2022 16:39:07 GMT [INFO] [index] Starting bot...
Thu, 01 Dec 2022 16:39:07 GMT [INFO] [index] Resolving management room...
Creating Web APIs
Thu, 01 Dec 2022 16:39:07 GMT [INFO] [index] Mjolnir is starting up. Use !mjolnir to query status.
Starting web server
Thu, 01 Dec 2022 16:39:07 GMT [INFO] [ProtectedRoomsConfig] Resolving protected rooms...
/data/home/mjolnir/mjolnir.git/lib/utils.js:32
    return input.replace(/["&<>]/g, (char) => ({
                 ^
TypeError: input.replace is not a function
    at htmlEscape (/data/home/mjolnir/mjolnir.git/lib/utils.js:32:18)
    at ManagementRoomOutput.logMessage (/data/home/mjolnir/mjolnir.git/lib/ManagementRoomOutput.js:102:56)
    at ProtectionManager.start (/data/home/mjolnir/mjolnir.git/lib/protections/ProtectionManager.js:66:51)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async Mjolnir.start (/data/home/mjolnir/mjolnir.git/lib/Mjolnir.js:250:13)
    at async /data/home/mjolnir/mjolnir.git/lib/index.js:79:9

It prints a single line to the managment room before immediately crashing: Mjolnir is starting up. Use !mjolnir to query status.

@bones-was-here
Copy link
Author

In 1.6.4 the line numbers changed but the crash is otherwise the same.

@Yoric
Copy link
Contributor

Yoric commented Jan 11, 2023

Apparently, it's crashing while attempting to display an error message, which is not very nice.

@Yoric
Copy link
Contributor

Yoric commented Jan 11, 2023

I won't have time to work on this but if you do, could you try replacing extractErrorMessage(e) with e.message in ProtectionManager.js and see if that improves the error message?

@bones-was-here
Copy link
Author

I don't normally use languages that don't have a compiler, but
In class ProtectionManager { async start() { I changed
this.mjolnir.managementRoomOutput.logMessage(matrix_bot_sdk_1.LogLevel.WARN, "ProtectionManager", (0, matrix_bot_sdk_1.extractRequestError)(e));
to
this.mjolnir.managementRoomOutput.logMessage(matrix_bot_sdk_1.LogLevel.WARN, "ProtectionManager", (0, e.message));
and the result is:

Wed, 11 Jan 2023 14:48:52 GMT [INFO] [index] Starting bot...
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [index] Resolving management room...
Creating Web APIs
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [index] Mjolnir is starting up. Use !mjolnir to query status.
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [Mjolnir] Starting Mjolnir instance
Starting web server
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [OpenMetrics server is disabled.]
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [ProtectedRoomsConfig] Resolving protected rooms...
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [INFO] [Mjolnir@startup] Checking permissions...
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:52 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:53 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:53 GMT [WARN] [ProtectionManager] Cannot read properties of undefined (reading 'includes')
Wed, 11 Jan 2023 14:48:53 GMT [ERROR] [MatrixHttpClient] (REQ-41) [Error: Error during MatrixClient request GET /_matrix/client/v3/user/%40xonbot%3Axonotic.org/account_data/m.direct: 404 Not Found -- {"errcode":"M_NOT_FOUND","error":"data not found"}]
Wed, 11 Jan 2023 14:48:53 GMT [INFO] [Mjolnir@startup] Syncing lists...
Wed, 11 Jan 2023 14:48:53 GMT [INFO] [Mjolnir@startup] Startup complete. Now monitoring rooms.

I havn't told it to do anything, but logging to the management room and !mjolnir seem to work :)

@Yoric
Copy link
Contributor

Yoric commented Jan 11, 2023

Ok, I think I see the problem, it's in your configuration rather than Mjölnir, although Mjölnir should probably be more defensive when reading that. Generally, instead of setting a configuration key to {} (which has an unexpected type/shape), just remove the key entirely.

@bones-was-here
Copy link
Author

My understanding is it's impossible to delete matrix state events, so after previously having issues with mjolnir and wanting a "clean slate" to test newer versions, I just set them all to empty content, eg

{
  "content": {},
  "type": "org.matrix.mjolnir.protected_rooms"
}

Is there a better option?

I also have in yaml config

protectedRooms:
  [] # crashes if we just have nothing here

Which was suggested in chat by Gnuxie. IMO it should be possible to run without any "hard coded" protected rooms, so that people who are moderators but aren't sysadmins can disable the protection on any given room if they need to.

@Yoric
Copy link
Contributor

Yoric commented Jan 12, 2023

Yeah, that would absolutely be better.
I'll see what I can do but my tenure as Mjölnir owner ends today, so not sure I'll have time to get something done.

@Yoric
Copy link
Contributor

Yoric commented Jan 12, 2023

I have a prototype solution in #468. I probably won't have time to finish and merge it, though.

@turt2live
Copy link
Member

I'm presuming this is fixed. If not, a new issue with more detail (including more logs) is best.

@turt2live turt2live closed this as not planned Won't fix, can't repro, duplicate, stale Oct 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants