d99kris / nchat

Terminal-based Telegram / WhatsApp client for Linux and macOS
MIT License
742 stars 48 forks source link

Extreme resource usage until system freezes - "Wrong database encryption key" #270

Closed kumraa-1 closed 3 months ago

kumraa-1 commented 3 months ago

Description: The program gives the following error twice every millisecond!!

" (tgchat.cpp:2182) 2024-08-01 14:14:26.476 | WARN | auth error "error { code = 401 message = "Wrong database encryption key" }

This stresses the cpu completely and memory is getting used up very fast until my system freezes. I got 8GB of RAM and it takes around 2 minutes until it's full.

Although it says auth error, Telegram works fine, I can chat without problems.

The program was built with the provided script.

How to reproduce it: Sign in with Telegram and just run the app. After 1-2 minutes my systems RAM is completely used and the system freezes.

Environment:

d99kris commented 3 months ago

Hi @kumraa-1 - thanks for reporting, it sounds like a bad bug. Would it be possible for you to zip the log file and attach here? Alternatively share the first ~10 lines of the log and the ~10 lines before this error first occurs?

I don't see the issue on my systems, but I suspect it's some special/error scenario not handled gracefully by nchat.

As a temporary workaround, you could try deleting the config dir (~/.nchat or ~/.config/nchat depending on your system) and run a fresh setup with nchat -s

Btw, did it work fine before, and suddenly started having this issue? And any ideas on what could've caused it - did you recently update nchat, or make changes to Telegram authentication settings/password, etc?

Thanks!

Edit: If you'd rather not share the log here in public, feel free to share it privately via email to d99kris at gmail dot com.

kumraa-1 commented 3 months ago

Hi! I sadly couldn't reproduce it after deleting the config folder and setting up telegram and whatsapp again. I also sadly wrote over the original log file.

I had it hang up on me now after I set up whatsapp, using 100% CPU again and giving hundreds of this error: 2024-08-01 19:40:52.161 | WARN | Chat settings not found (gowm.go:719)

Here's the log

2024-08-01 19:39:23.889 | INFO  | nchat 5.1.20  (main.cpp:249)
2024-08-01 19:39:23.890 | INFO  | Debian GNU/Linux trixie/sid x86_64  (main.cpp:251)
2024-08-01 19:39:23.890 | INFO  | GCC 14.1.0 glibc 2.39  (main.cpp:253)
2024-08-01 19:39:23.890 | INFO  | Go 1.22.5  (main.cpp:255)
2024-08-01 19:39:23.890 | INFO  | Telegram ON, WhatsApp ON  (main.cpp:257)
2024-08-01 19:39:32.981 | INFO  | whatsmeow Upgrading database to v1  (gowm.go:478)
2024-08-01 19:39:32.988 | INFO  | whatsmeow Upgrading database to v2  (gowm.go:478)
2024-08-01 19:39:32.992 | INFO  | whatsmeow Upgrading database to v3  (gowm.go:478)
2024-08-01 19:39:32.995 | INFO  | whatsmeow Upgrading database to v4  (gowm.go:478)
2024-08-01 19:39:32.997 | INFO  | whatsmeow Upgrading database to v5  (gowm.go:478)
2024-08-01 19:39:33.000 | INFO  | whatsmeow Upgrading database to v6  (gowm.go:478)
2024-08-01 19:39:33.010 | INFO  | create base db schema  (messagecache.cpp:264)
2024-08-01 19:39:33.011 | INFO  | update db schema 3 to 4  (messagecache.cpp:304)
2024-08-01 19:39:33.027 | INFO  | has gui  (gowm.go:385)
2024-08-01 19:39:50.579 | INFO  | whatsmeow Successfully paired 436764976100:34@s.whatsapp.net  (gowm.go:478)
2024-08-01 19:39:51.156 | INFO  | whatsmeow Got 515 code, reconnecting...  (gowm.go:478)
2024-08-01 19:39:52.695 | INFO  | whatsmeow Successfully authenticated  (gowm.go:478)
2024-08-01 19:39:53.844 | INFO  | whatsmeow Uploading 50 new prekeys to server  (gowm.go:478)
2024-08-01 19:39:55.355 | INFO  | load telegram profile  (tgchat.cpp:336)
2024-08-01 19:39:55.362 | INFO  | ui loop start  (ui.cpp:96)
2024-08-01 19:39:55.414 | WARN  | tmp  (gowm.go:2325)
2024-08-01 19:39:55.465 | WARN  | tmp  (gowm.go:2325)
2024-08-01 19:39:56.680 | INFO  | whatsmeow Updating contact store with 46 push names from history sync  (gowm.go:478)
2024-08-01 19:39:57.080 | WARN  | Chat settings not found  (gowm.go:719)
2024-08-01 19:39:57.092 | INFO  | whatsmeow Stored 27 privacy tokens from history sync  (gowm.go:478)
2024-08-01 19:39:57.099 | WARN  | Chat settings not found  (gowm.go:719)
2024-08-01 19:39:57.100 | WARN  | Chat settings not found  (gowm.go:719)
... and so on ...

I cant tell if it worked fine before because I just installed it and never had it open for longer than 1 min, so I didn't really notice the weird behavior.

I'd close the issue for now and report back if anything funny happens again.

d99kris commented 3 months ago

So the log issues you mentioned are specific for each protocol. This can only be logged when using Telegram:

2024-08-01 14:14:26.476 | WARN  | auth error "error { code = 401 message = "Wrong database encryption key" } 
 (tgchat.cpp:2182)

And the following can only be encountered when using WhatsApp:

2024-08-01 19:39:57.099 | WARN  | Chat settings not found  (gowm.go:719)

For the WhatsApp warning I have pushed a code change dee42e7 lowering the log level for that message, it's not really an issue so should not be a warning. Thanks for highlighting it!

Regarding 100% CPU usage directly at WhatsApp setup, it might not point to an issue. During the initial sync for WhatsApp (top right status says Syncing) the CPU usage might be high, and this can last for a few seconds or up to a couple of minutes, depending on how much history the account has (I think around 1 years history is synced). But if it slows down interaction inside nchat or continues to have high CPU usage after Syncing is completed, then I would consider it an issue.

I will proceed to close this issue for now. But if you encounter 100% CPU usage again (at anytime with Telegram, or with WhatsApp at any time after first time setup sync), feel free to re-open the issue. Thanks!

d99kris commented 3 months ago

In bug #272 the "Wrong database encryption key" was reported again, and a fix for that was implemented in 40d7e37.