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

silverbullet crashes after restarting the service #354003

Open
gepbird opened this issue Nov 6, 2024 · 3 comments
Open

silverbullet crashes after restarting the service #354003

gepbird opened this issue Nov 6, 2024 · 3 comments
Labels
0.kind: bug Something is broken

Comments

@gepbird
Copy link
Contributor

gepbird commented Nov 6, 2024

Describe the bug

After restarting the silverbullet service, it crashes. The first start works when there is no data in /var/lib/silverbullet, but as soon as that gets generated, trying to start silverbullet again fails.

Steps To Reproduce

Steps to reproduce the behavior:

  1. Go into your fork of nixpkgs and apply this patch to the existing nixos test:
diff --git a/nixos/tests/silverbullet.nix b/nixos/tests/silverbullet.nix
index e7e3cf536558..995eec7128e9 100644
--- a/nixos/tests/silverbullet.nix
+++ b/nixos/tests/silverbullet.nix
@@ -43,5 +43,9 @@ import ./make-test-python.nix ({ lib, ... }: {
     assert int(configured.succeed(f"curl --max-time 5 -s -o /dev/null -w '%{{http_code}}' -XPUT -d 'test' --fail http://{ADDRESS}:{PORT}/test.md -H'Authorization: Bearer test'")) == 200
     assert int(configured.fail(f"curl --max-time 5 -s -o /dev/null -w '%{{http_code}}' -XPUT -d 'test' --fail http://{ADDRESS}:{PORT}/test.md -H'Authorization: Bearer wrong'")) == 401
     configured.succeed(f"test -d '{SPACEDIR}'")
+
+    configured.succeed("systemctl restart silverbullet.service")
+    configured.execute("sleep 15") # wait_for_unit doesn't seem to work here
+    assert int(configured.succeed(f"curl --max-time 5 -s -o /dev/null -w '%{{http_code}}' -XPUT -d 'test' --fail http://{ADDRESS}:{PORT}/test.md -H'Authorization: Bearer test'")) == 200
   '';
 })
  1. Run nix build .#nixosTests.silverbullet
  2. Observe the failure

Logs

silverbullet.service log after restart (trimmed)
Using KV as a database backend (/home/test/silverbullet/.silverbullet.db).
Going to start SilverBullet binding to localhost:3001
Using local disk as a storage backend: /home/test/silverbullet
Unhandled rejection: PromiseRejectionEvent {
  bubbles: false,
  cancelable: true,
  composed: false,
  currentTarget: Window {},
  defaultPrevented: false,
  eventPhase: 2,
  srcElement: null,
  target: Window {},
  returnValue: true,
  timeStamp: 0,
  type: "unhandledrejection",
  promise: Promise {
    <rejected> ReferenceError: window is not defined
    at IV.hashSHA256 (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:87:33860)
    at IV.init (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:87:33272)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async zX.init (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2384:18073)
    at async rX.start (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2385:7437)
    at async F.gj [as actionHandler] (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2385:13469244)
    at async F.execute (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:24:8601)
    at async F.parseCommand (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:24:6314)
    at async file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2418:6541
  },
  reason: ReferenceError: window is not defined
    at IV.hashSHA256 (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:87:33860)
    at IV.init (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:87:33272)
    at eventLoopTick (ext:core/01_core.js:175:7)
    at async zX.init (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2384:18073)
    at async rX.start (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2385:7437)
    at async F.gj [as actionHandler] (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2385:13469244)
    at async F.execute (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:24:8601)
    at async F.parseCommand (file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:24:6314)
    at async file:///nix/store/w55cjcm10y9qidjxcjd5kq6x1mj9bh76-silverbullet-0.9.4/lib/silverbullet.js:2418:6541
}

Expected behavior

Test should pass.

Additional context

I noticed this issue when trying to set up silverbullet on our raspberry pi 4. Another thing is this issue doesn't happen without setting SB_USER and SB_AUTH_TOKEN environment variables.

Notify maintainers

cc @aorith

Metadata

 - system: `"aarch64-linux"`
 - host os: `Linux 6.11.5, NixOS, 24.11 (Vicuna), 24.11.20241025.dirty`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Lix, like Nix) 2.91.1
System type: aarch64-linux
Additional system types:
Features: gc, signed-caches
System configuration file: /etc/nix/nix.conf
User configuration files: /home/gep/.config/nix/nix.conf:/etc/xdg/nix/nix.conf:/home/gep/.nix-profile/etc/xdg/nix/nix.conf:/nix/profile/etc/xdg/nix/nix.conf:/home/gep/.local/state/nix/profile/etc/xdg/nix/nix.conf:/etc/profiles/per-user
/gep/etc/xdg/nix/nix.conf:/nix/var/nix/profiles/default/etc/xdg/nix/nix.conf:/run/current-system/sw/etc/xdg/nix/nix.conf
Store directory: /nix/store
State directory: /nix/var/nix
Data directory: /nix/store/f109fmh4i01j5h5l5b5qd2lmas1v8y8j-lix-2.91.1/share`
 - nixpkgs: `/nix/store/chnzzrb2jz9998kwxlwy43sm9rayd9l0-source`

Add a 👍 reaction to issues you find important.

@gepbird gepbird added the 0.kind: bug Something is broken label Nov 6, 2024
@aorith
Copy link
Contributor

aorith commented Nov 6, 2024

Thank you for the detailed report =)
It seems to be an issue with upstream not supporting deno2 yet.

#347484

This commit still has deno_1 package: dfce2bc
If I replace deno for deno_1 at pkgs/by-name/si/silverbullet/package.nix to pin deno 1.46.x it works, with deno 2.x it fails (after the first run has created the database):

mkdir -p /tmp/test
SB_USER=test SB_AUTH_TOKEN=user:1234 ./result/bin/silverbullet --hostname 127.0.0.1 /tmp/test

@aorith
Copy link
Contributor

aorith commented Nov 6, 2024

Upstream already supports deno2 on their "edge" version so it's a matter of time until they release the next version :)

@gepbird
Copy link
Contributor Author

gepbird commented Nov 6, 2024

Thanks for finding this out!

Works when I pin it to deno_1, this might be useful for other people:

services.silverbullet = {
  package = pkgs.silverbullet.override {
    deno = pkgs.deno_1;
  };
};

I assume downgrading it to deno_1 in nixpkgs doesn't help much because it will be dropped soon. So we could either switch to that less stable edge version or wait for a new release depending on how far is that.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: bug Something is broken
Projects
None yet
Development

No branches or pull requests

2 participants