donaldzou / WGDashboard

Simple dashboard for WireGuard VPN written in Python & Vue.js
https://donaldzou.github.io/WGDashboard-Documentation/
Apache License 2.0
1.65k stars 254 forks source link

Panel crash #366

Closed sohrabp72 closed 2 months ago

sohrabp72 commented 2 months ago

Describe The Problem After removing more than 10 peers it pannel crashs. After restricting and allowing some peers this crash happened again.

Expected Error / Traceback

[2024-09-04 23:09:14 +0000] [1434] [INFO] Starting gunicorn 23.0.0
[2024-09-04 23:09:14 +0000] [1434] [INFO] Listening at: http://0.0.0.0:10086 (1434)
[2024-09-04 23:09:14 +0000] [1434] [INFO] Using worker: gthread
[2024-09-04 23:09:14 +0000] [1436] [INFO] Booting worker with pid: 1436
[WGDashboard] Background Thread #1 Started
[WGDashboard] Background Thread #2 Started
[2024-09-04 23:11:36,849] ERROR in app: Exception on /api/getWireguardConfigurationInfo [GET]
Traceback (most recent call last):
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/app.py", line 1473, in wsgi_app
    response = self.full_dispatch_request()
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/app.py", line 882, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask_cors/extension.py", line 178, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/app.py", line 880, in full_dispatch_request
    rv = self.dispatch_request()
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/app.py", line 865, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**view_args)  # type: ignore[no-any-return]
  File "/root/WGDashboard/src/dashboard.py", line 1902, in API_getConfigurationInfo
    return ResponseObject(data={
  File "/root/WGDashboard/src/dashboard.py", line 71, in ResponseObject
    response = Flask.make_response(app, {
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/app.py", line 1193, in make_response
    rv = self.json.response(rv)
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/json/provider.py", line 214, in response
    f"{self.dumps(obj, **dump_args)}\n", mimetype=self.mimetype
  File "/root/WGDashboard/src/venv/lib/python3.10/site-packages/flask/json/provider.py", line 179, in dumps
    return json.dumps(obj, **kwargs)
  File "/usr/lib/python3.10/json/__init__.py", line 238, in dumps
    **kw).encode(obj)
  File "/usr/lib/python3.10/json/encoder.py", line 199, in encode
    chunks = self.iterencode(o, _one_shot=True)
  File "/usr/lib/python3.10/json/encoder.py", line 257, in iterencode
    return _iterencode(o, 0)
  File "/root/WGDashboard/src/dashboard.py", line 91, in default
    return o.toJson()
  File "/root/WGDashboard/src/dashboard.py", line 950, in toJson
    self.getShareLink()
  File "/root/WGDashboard/src/dashboard.py", line 1054, in getShareLink
    self.ShareLink = AllPeerShareLinks.getLink(self.configuration.Name, self.id)
  File "/root/WGDashboard/src/dashboard.py", line 411, in getLink
    self.__getSharedLinks()
  File "/root/WGDashboard/src/dashboard.py", line 406, in __getSharedLinks
    allLinks = sqlSelect("SELECT * FROM PeerShareLinks WHERE ExpireDate IS NULL OR ExpireDate > datetime('now', 'localtime')").fetchall()
  File "/root/WGDashboard/src/dashboard.py", line 1402, in sqlSelect
    with sqldb:
sqlite3.OperationalError: cannot commit - no transaction is active

To Reproduce Normally installed on the server, no docker.

OS Information:

Sample of your .conf file [Interface] Address = 10.252.1.0/24 PreUp = sysctl -w net.ipv4.ip_forward=1 PreUp = iptables -t mangle -A PREROUTING -i wg0 -j MARK --set-mark 0x30 PreUp = iptables -t nat -A POSTROUTING ! -o wg0 -m mark --mark 0x30 -j MASQUERADE PostDown = iptables -t mangle -D PREROUTING -i wg0 -j MARK --set-mark 0x30 PostDown = iptables -t nat -D POSTROUTING ! -o wg0 -m mark --mark 0x30 -j MASQUERADE ListenPort = 26840 (port is changed for security reasons) PrivateKey = ABCD

[Peer] PublicKey = 7GacYlIQdZNIeK7N364Ix7WNBrVv4FiyqEsRW/9Wqys= AllowedIPs = 10.252.1.15/32 Endpoint = 127.0.0.1:54134

mzs114 commented 2 months ago

Hi, if you check the requirements it says Python 3.10 or above, maybe that is the reason? The error states that it could not commit to the sqlite DB, maybe due to permissions on the filesystem, but as you would git cloned the setup, it does not seem likely, do check with the below command, ouput from my setup.

ls -l WGDashboard/src/db/ total 596 -rw-r--r-- 1 root root 49152 Aug 28 10:31 wgdashboard.db -rw-r--r-- 1 root root 12288 Aug 27 09:32 wgdashboard_job.db -rw-r--r-- 1 root root 544768 Sep 4 11:32 wgdashboard_log.db

donaldzou commented 2 months ago

This is due to the nature of async access of SQLite.. I'm trying to fix this issue

donaldzou commented 2 months ago

Refer to #354

mzs114 commented 2 months ago

This is due to the nature of async access of SQLite.. I'm trying to fix this issue

Thank you, but for the time being is there a workaround for the users?

donaldzou commented 2 months ago

@sohrabp72, do you mind trying out this branch?

git clone https://github.com/donaldzou/WGDashboard -b Fix-#353

sohrabp72 commented 2 months ago

Hi, if you check the requirements it says Python 3.10 or above, maybe that is the reason? The error states that it could not commit to the sqlite DB, maybe due to permissions on the filesystem, but as you would git cloned the setup, it does not seem likely, do check with the below command, ouput from my setup.

ls -l WGDashboard/src/db/ total 596 -rw-r--r-- 1 root root 49152 Aug 28 10:31 wgdashboard.db -rw-r--r-- 1 root root 12288 Aug 27 09:32 wgdashboard_job.db -rw-r--r-- 1 root root 544768 Sep 4 11:32 wgdashboard_log.db

This is not the case. ls -l WGDashboard/src/db/ total 1884 -rw-r--r-- 1 root root 196608 Sep 5 11:33 wgdashboard.db -rw-r--r-- 1 root root 12288 Aug 20 03:56 wgdashboard_job.db -rw-r--r-- 1 root root 1712128 Sep 5 11:32 wgdashboard_log.db

sohrabp72 commented 2 months ago

@sohrabp72, do you mind trying out this branch?

git clone https://github.com/donaldzou/WGDashboard -b Fix-#353

I would not as many peers are connected and I have no backup of the panel, any problem on the way makes trouble.