2e3s / awatcher

Activity and idle watchers
Mozilla Public License 2.0
134 stars 4 forks source link

"DB worker quitting, error: RecvError" error #11

Closed stephane-klein closed 8 months ago

stephane-klein commented 9 months ago

Hello,

I have installed awatcher with this script.

I have setup this systemctl service ~/.config/systemd/user/awatcher.service :

[Service]
Type=simple
ExecStart=${HOME}/.local/opt/activitywatch/awatcher

[Unit]
Description=ActivityWatch Server (Rust implementation)
Wants=network.target

[Install]
WantedBy=default.target

I have enabled this service :

$ chmod 644 ~/.config/systemd/user/awatcher.service
$ systemctl --user daemon-reload
$ systemctl --user start awatcher.service
$ systemctl --user enable awatcher.service

When my Fedora 39, Gnome 45.3 (Wayland) session start, I have this error:

$ systemctl --user status awatcher.service
○ awatcher.service - ActivityWatch Server (Rust implementation)
     Loaded: loaded (/home/stephane/.config/systemd/user/awatcher.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/user/service.d
             └─10-timeout-abort.conf
     Active: inactive (dead) since Sat 2024-01-20 11:38:34 CET; 15min ago
   Duration: 207ms
   Main PID: 3740 (code=exited, status=0/SUCCESS)
        CPU: 118ms

janv. 20 11:38:34 t14s systemd[3719]: Started awatcher.service - ActivityWatch Server (Rust implementation).
janv. 20 11:38:34 t14s awatcher[3740]: [2024-01-20 10:38:34.436493 WARN rocket::launch] 🚀 Rocket has launched from http://127.0.0.1:5600
janv. 20 11:38:34 t14s awatcher[3740]: [2024-01-20 10:38:34.469842 ERROR aw_datastore::worker] DB worker quitting, error: RecvError

I don't understand why I have "DB worker quitting, error: RecvError" error 🤔.

If I execute:

$ systemctl --user start awatcher.service
$ systemctl --user status awatcher.service
● awatcher.service - ActivityWatch Server (Rust implementation)
     Loaded: loaded (/home/stephane/.config/systemd/user/awatcher.service; enabled; preset: disabled)
    Drop-In: /usr/lib/systemd/user/service.d
             └─10-timeout-abort.conf
     Active: active (running) since Sat 2024-01-20 11:54:36 CET; 1s ago
   Main PID: 15641 (awatcher)
      Tasks: 7 (limit: 36945)
     Memory: 5.6M
        CPU: 68ms
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/awatcher.service
             └─15641 /home/stephane/.local/opt/activitywatch/awatcher

janv. 20 11:54:36 t14s systemd[3719]: Started awatcher.service - ActivityWatch Server (Rust implementation).
janv. 20 11:54:36 t14s awatcher[15641]: [2024-01-20 10:54:36.896408 WARN rocket::launch] 🚀 Rocket has launched from http://127.0.0.1:5600

I have no error.

At the moment, I don't know what direction to look in to correct this problem.

If you have an idea, I'd love to hear from you.

Best regards, Stéphane

2e3s commented 9 months ago

Hello!

DB worker quitting, error: RecvError

This is kind of normal (needs fixing but no effect on the functionality), it's always thrown after the program exists. What's really happening, I assume, it is that the program can't find protocol to work with. Could you please turn on more verbose logging with -vvv option and give the logs?

Also, for Gnome, do you have the prerequisites from the readme installed? Although, if it is able to work in different conditions, I guess it's installed.

stephane-klein commented 9 months ago

@2e3s thanks 🤗.

Could you please turn on more verbose logging with -vvv option and give the logs?

Yes, here is log with -vvv option:

janv. 21 08:35:56 t14s awatcher[15641]: [2024-01-21 07:35:56.801234 ERROR watchers::watchers] Error on active window iteration: DBus interface org.gnome.shell.extensions.FocusedWindow returned wrong JSON
janv. 21 08:35:57 t14s awatcher[15641]: [2024-01-21 07:35:57.805963 ERROR watchers::watchers] Error on active window iteration: DBus interface org.gnome.shell.extensions.FocusedWindow returned wrong JSON
janv. 21 08:35:58 t14s awatcher[15641]: [2024-01-21 07:35:58.813876 ERROR watchers::watchers] Error on active window iteration: DBus interface org.gnome.shell.extensions.FocusedWindow returned wrong JSON
janv. 21 08:35:59 t14s awatcher[15641]: [2024-01-21 07:35:59.817045 ERROR watchers::watchers] Error on active window iteration: DBus interface org.gnome.shell.extensions.FocusedWindow returned wrong JSON
janv. 21 08:36:01 t14s awatcher[15641]: [2024-01-21 07:36:01.362594 ERROR watchers::watchers] Error on active window iteration: org.freedesktop.DBus.Error.NoReply: Remote peer disconnected
janv. 21 08:36:01 t14s awatcher[15641]: thread '<unnamed>' panicked at /home/runner/.cargo/registry/src/index.crates.io-6f17d22bba15001f/ksni-0.2.1/src/service.rs:85:37:
janv. 21 08:36:01 t14s awatcher[15641]: called `Result::unwrap()` on an `Err` value: D-Bus error: Failed to read/write data, disconnected from D-Bus? (org.freedesktop.DBus.Error.Failed)
janv. 21 08:36:01 t14s awatcher[15641]: note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
janv. 21 08:36:01 t14s awatcher[15641]: [2024-01-21 07:36:01.399131 ERROR aw_datastore::worker] DB worker quitting, error: RecvError
janv. 21 08:36:01 t14s systemd[3719]: awatcher.service: Consumed 15.355s CPU time.
stephane-klein commented 9 months ago

Also, for Gnome, do you have the prerequisites from the readme installed?

Yes, I assume it's about: https://extensions.gnome.org/extension/5592/focused-window-d-bus/ ?

2e3s commented 8 months ago

Yes, I assume it's about: extensions.gnome.org/extension/5592/focused-window-d-bus ?

Yes.

I have no error.

I assume, the tray icon and the web UI work ok and applications are tracked in this case?

org.gnome.shell.extensions.FocusedWindow returned wrong JSON

Not enough logging here https://github.com/2e3s/awatcher/blob/main/watchers/src/watchers/gnome_window.rs#L41 I will enhance the logging, but what I suspect from your initial description, it is that Gnome extension doesn't have time to load before awatcher starts.

I think it's related to https://github.com/2e3s/awatcher/issues/8 . I'm trying to recreate your setup locally thanks for your thorough description.

2e3s commented 8 months ago

I've added this to the service file and it seems to work:

ExecStartPre=/bin/sleep 5

It posted 1 time Error on active window iteration: DBus interface org.gnome.shell.extensions.FocusedWindow returned wrong JSON, I'll look to know why, but then went on tracking normally (My setup is a freshly installed Ubuntu 23.10 on VM).

stephane-klein commented 8 months ago

I think it's related to https://github.com/2e3s/awatcher/issues/8 .

Yes :+1:

2e3s commented 8 months ago

I've attempted to improve the convenience with this change: https://github.com/2e3s/awatcher/releases/tag/v0.2.4-alpha2 However, it's appropriate only for Gnome Tweaks which seems to work for me. I've added a description to autostart https://github.com/2e3s/awatcher/commit/94de477f3fafba68c731bda964b09279a282fde0 Please close the issue if autostart works for you.

stephane-klein commented 8 months ago

Systemd may require to sleep for a few seconds (ExecStartPre=/bin/sleep 5) in order to wait for the environment.

This method is working on my laptop.

Then, I close the issue.