Skip to content

refactor(wireguard): ip allocation refactor - #713

Merged
M03ED merged 7 commits into
devfrom
wg-ip-allocation-refactor
Jul 23, 2026
Merged

refactor(wireguard): ip allocation refactor#713
M03ED merged 7 commits into
devfrom
wg-ip-allocation-refactor

Conversation

@M03ED

@M03ED M03ED commented Jul 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Type of change

  • Bug fix
  • New feature
  • Breaking change
  • Refactor / cleanup
  • Documentation
  • Tests / CI

Checklist

  • I tested the change locally or explained why it cannot be tested.
  • I added or updated tests for behavior changes.
  • I updated documentation, translations, or examples if needed.
  • I checked database migrations when models or schema changed.
  • I did not include secrets, tokens, private keys, or unrelated changes.

Summary by CodeRabbit

  • New Features

    • Added automatic WireGuard subnet-based peer IP allocation and reconciliation.
    • Added subnet capacity and free-address reporting through a new system API endpoint.
    • Added bulk proxy settings updates.
    • Added WireGuard subnet validation and recovery when cores change.
  • Bug Fixes

    • Broken core configurations are now skipped without preventing startup.
    • WireGuard allocations stay synchronized when users or groups change.
  • Updates

    • Removed manual WireGuard peer IP editing and bulk reallocation tools.
    • Removed legacy WireGuard pool configuration options.

M03ED added 2 commits July 20, 2026 18:02
- Add `wireguard.py` for handling WireGuard subnet allocation, including functions for managing peer IPs, namespaces, and user allocations.
- Introduce `wireguard_subnets` table migration to store subnet allocation data, including next offsets and free offsets.
- Implement backfill logic for existing users' peer IPs during migration, ensuring proper allocation based on core configurations.
- Create unit tests for WireGuard allocation logic, covering subnet management, IP rendering, and allocation functions.
@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown

Review Change Stack

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: e3e8dfff-6bcf-4aa3-83ac-80c7f65eebb5

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Walkthrough

The PR replaces global WireGuard peer-IP allocation with subnet-aware database pools, lifecycle reconciliation, key preparation, migration backfill, and subnet usage reporting. It also removes manual bulk peer-IP management from the API and dashboard and makes core initialization skip invalid configurations.

Changes

WireGuard allocation and persistence

Layer / File(s) Summary
Subnet allocation engine
app/db/crud/wireguard.py, app/db/models.py, app/models/system.py, tests/test_wireguard_alloc_unit.py
Adds namespace derivation, reserved-offset handling, persistent allocation pools, reconciliation, release logic, and subnet usage reporting with unit coverage.
Migration backfill
app/db/migrations/versions/...
Creates wireguard_subnets and migrates existing WireGuard peer addresses into subnet-aware allocation state.
Lifecycle synchronization
app/db/crud/user.py, app/operation/core.py, app/operation/group.py, app/operation/user.py, app/utils/wireguard.py
Synchronizes allocations across user, group, and core changes; manages keys separately; maps subnet exhaustion to HTTP 400.
API and subscription integration
app/routers/system.py, app/subscription/share.py
Adds GET /wireguard/subnets and selects peer addresses matching each WireGuard inbound.
Allocation behavior tests
tests/api/test_user.py, tests/api/test_bulk.py
Tests subnet allocation, overlap validation, shared namespaces, resizing, release/reuse, and exhaustion behavior.

Removal of manual WireGuard peer-IP management

Layer / File(s) Summary
Backend bulk surface
app/db/crud/bulk.py, app/models/user.py, app/routers/user.py, dashboard/src/service/api/index.ts
Removes bulk peer-IP reallocation models, queries, operation methods, endpoint wiring, and generated API helpers; adds bulk proxy-settings routing.
Dashboard flow and forms
dashboard/src/features/bulk/*, dashboard/src/features/users/*, dashboard/src/app/router.tsx, dashboard/src/pages/_dashboard.bulk*
Removes the WireGuard bulk route, controls, mutation flow, peer-IP form field, and peer-IP form schema values.
Navigation and translations
dashboard/src/components/layout/*, dashboard/public/statics/locales/*, dashboard/src/utils/rbac.ts
Removes WireGuard bulk navigation, headers, permissions, icons, and peer-IP translation strings.
Configuration cleanup
.env.example, config.py, app/db/migrations/versions/a1b2c3d4e5f6_add_wireguard_settings_to_proxy_settings.py
Removes global WireGuard pool settings and legacy migration allocation behavior.

Core loading resilience and formatting

Layer / File(s) Summary
Invalid core handling
app/core/manager.py, tests/test_core_manager_skip_broken.py
Logs validation failures and skips broken cores during startup or local updates, with coverage for startup behavior.
Non-functional formatting updates
app/models/host.py, app/models/reality_scan.py, app/utils/reality_scan.py, tests/test_reality_scan_unit.py
Reformats field declarations, expressions, annotations, exception syntax, and matching test calls without changing the summarized intended values.

Estimated code review effort: 5 (Critical) | ~120 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Admin
  participant CoreOperation
  participant wireguard
  participant Database
  participant Subscription
  Admin->>CoreOperation: create or modify WireGuard core
  CoreOperation->>wireguard: reconcile_wireguard_subnets
  wireguard->>Database: rebuild subnet pools and user peer_ips
  Database-->>wireguard: reconciled allocation state
  wireguard-->>CoreOperation: affected user ids
  CoreOperation->>Subscription: resync affected users
  Subscription->>wireguard: pick_peer_ip_for_inbound
  wireguard-->>Subscription: inbound-matching peer_ips
Loading

Possibly related PRs

  • PasarGuard/panel#271: Updates user group assignment flows that this PR now uses to trigger WireGuard allocation synchronization.

Suggested labels: Backend

Suggested reviewers: x0sina

Poem

I’m a rabbit with addresses neat,
Allocating each subnet a seat.
Old bulk paths hop away,
New pools guide the day,
And broken cores skip to retreat.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 19.79% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the PR’s main change: a WireGuard IP allocation refactor.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch wg-ip-allocation-refactor

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@ImMohammad20000 ImMohammad20000 changed the title Wg ip allocation refactor refactor: Wg ip allocation refactor Jul 20, 2026
@M03ED M03ED changed the title refactor: Wg ip allocation refactor feat(wireguard): ip allocation refactor Jul 20, 2026
@M03ED M03ED changed the title feat(wireguard): ip allocation refactor refactor(wireguard): ip allocation refactor Jul 20, 2026
@M03ED

M03ED commented Jul 20, 2026

Copy link
Copy Markdown
Contributor Author

@coderabbitai review

@coderabbitai

coderabbitai Bot commented Jul 20, 2026

Copy link
Copy Markdown
✅ Action performed

Review finished.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@coderabbitai coderabbitai Bot added the Backend label Jul 20, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
app/operation/user.py (1)

819-834: 🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Bulk template apply can surface an unhandled 500 on WireGuard subnet exhaustion.

_apply_modified_user now wraps crud_modify_user in try/except ValueError to translate WG subnet exhaustion into a 400 (Line 831-834). However bulk_apply_template_to_users calls crud_modify_user directly in its own loop and only catches generic Exception to rollback-and-re-raise (no ValueError→400 translation). Since load_base_user_args sets group_ids from the template, applying a template that assigns a WG group to many users can legitimately trigger the same "subnet exhausted" ValueError from crud_modify_user, but here it will propagate raw instead of becoming a clean 400 — inconsistent with every other WG-exhaustion path in this file (create_user, _persist_bulk_users, _apply_modified_user).

🔧 Proposed fix
         try:
             for db_user, modified_user_model, validated_groups, _, _ in prepared_updates:
                 if user_template.reset_usages:
                     await reset_user_data_usage(
                         db,
                         db_user,
                         clean_chart_data=usage_settings.reset_user_usage_clean_chart_data,
                         commit=False,
                     )

                 self._apply_explicit_null_hwid_limit(db_user, modified_user_model)
-                await crud_modify_user(
-                    db,
-                    db_user,
-                    modified_user_model,
-                    groups=validated_groups,
-                    commit=False,
-                )
+                try:
+                    await crud_modify_user(
+                        db,
+                        db_user,
+                        modified_user_model,
+                        groups=validated_groups,
+                        commit=False,
+                    )
+                except ValueError as exc:  # WireGuard subnet exhausted
+                    await self.raise_error(message=str(exc), code=400, db=db)
                 if db_user.id is not None:
                     modified_user_ids.append(db_user.id)

             await db.commit()
         except Exception:
             await db.rollback()
             raise
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/operation/user.py` around lines 819 - 834, Update
bulk_apply_template_to_users so its crud_modify_user loop catches WireGuard
subnet-exhaustion ValueError and translates it through the same raise_error(...,
code=400, db=...) path used by create_user, _persist_bulk_users, and
_apply_modified_user. Preserve the existing rollback behavior for other
exceptions.
app/utils/wireguard.py (1)

14-36: 🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

app/utils/wireguard.py:14-36 — Back WireGuard public_key uniqueness with a DB constraint

wireguard_public_key_in_use is only an application-side check. Without a unique index/constraint on users.proxy_settings->wireguard->public_key, concurrent create/update requests can still persist duplicate WireGuard keys and break peer identity for one user. Add a DB-backed uniqueness guarantee, or handle the resulting IntegrityError if it already exists.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/utils/wireguard.py` around lines 14 - 36, Add a database-level unique
constraint or unique index for the WireGuard public key JSON value used by
`wireguard_public_key_in_use`, and ensure create/update persistence handles any
resulting `IntegrityError` consistently. Keep the existing application-side
validation and allow users without a public key to remain unaffected.
🧹 Nitpick comments (2)
app/db/migrations/versions/3c1a7e5b9d20_add_wireguard_subnets_pool_table.py (1)

246-256: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Backfill free_offsets is not bounded like the runtime path.

The runtime allocator caps each row's free-list via _trim_free/FREE_OFFSETS_CAP (see app/db/crud/wireguard.py Lines 215-218, 524-526) to bound JSON size. This migration writes the full free list uncapped. When an existing peer IP is preserved at a high offset in a large subnet, next_offset becomes large and free can contain tens of thousands of entries, producing a bloated pool row until the next reconcile trims it. Apply the same cap here for consistency.

Proposed fix
         free = [
             offset
             for offset in range(1, next_offset)
             if offset not in offsets and offset not in ns["reserved"] and offset < ns["subnet"].num_addresses - 1
         ]
+        if len(free) > 10000:  # keep in sync with FREE_OFFSETS_CAP
+            free = sorted(free)[:10000]
         pool_rows.append({"network": key, "next_offset": next_offset, "free_offsets": free})
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/db/migrations/versions/3c1a7e5b9d20_add_wireguard_subnets_pool_table.py`
around lines 246 - 256, Cap the migration’s computed free offset list before
appending it to pool_rows, matching the runtime allocator’s
FREE_OFFSETS_CAP/_trim_free behavior in the wireguard CRUD path. Update the
free_offsets value in the loop over namespaces while preserving the existing
offset filtering and next_offset calculation.
app/utils/wireguard.py (1)

39-42: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Uncached get_wg_cores() lookup on every user prep call causes N+1 queries in bulk paths.

user_has_wireguard_access re-queries core_configs on every invocation with no caching, and it's invoked unconditionally on every single-user and bulk-user modify/create path — turning bulk operations into one extra DB round-trip per user for a value that's identical across the whole batch.

  • app/utils/wireguard.py#L39-L42: root cause — memoize/cache get_wg_cores(db) per request or accept a precomputed wg_tags/access flag instead of querying inside user_has_wireguard_access.
  • app/operation/user.py#L371-L378: _persist_bulk_users's per-user loop triggers one get_wg_cores query per created user; compute WG access once for the shared groups and reuse across the loop.
  • app/operation/user.py#L789-L813: _prepare_modified_user (called for every single modify_user) re-runs the same uncached check even for non-WG changes (e.g. pure status/note edits).
  • app/operation/user.py#L1125-L1136: _bulk_set_user_status's per-user loop compounds the same redundant query across all selected users.
  • app/operation/user.py#L1814-L1832: bulk_apply_template_to_users's per-user loop has the same N+1 pattern.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/utils/wireguard.py` around lines 39 - 42, The uncached WireGuard core
lookup causes one database query per user during bulk operations. Update
app/utils/wireguard.py lines 39-42 in user_has_wireguard_access to accept or
reuse precomputed wg_tags/access data, then compute that value once and reuse it
in app/operation/user.py lines 371-378 (_persist_bulk_users), 1125-1136
(_bulk_set_user_status), and 1814-1832 (bulk_apply_template_to_users); avoid
rechecking for unrelated changes in _prepare_modified_user at lines 789-813,
while preserving single-user access behavior.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/db/crud/wireguard.py`:
- Around line 382-384: Update new_ips construction in sync_users_allocations to
use the same canonical _peer_sort_key ordering as reconcile_wireguard_subnets
before comparing it with old_ips. Preserve the existing IP rendering and ensure
the comparison reflects peer changes rather than CIDR key ordering.
- Around line 206-212: In the group operation flow, wrap the
sync_users_allocations call in app/operation/group.py with ValueError handling
and return an HTTP 400 when WireGuard address allocation is exhausted. Preserve
reconcile_wireguard_subnets’s existing warn-and-continue behavior, and apply the
handling to both group and bulk-group changes without altering successful
synchronization.

In `@app/utils/reality_scan.py`:
- Line 184: Parenthesize the exception tuples in all three handlers in
app/utils/reality_scan.py: lines 184-184 should catch asyncio.TimeoutError and
TimeoutError as a tuple, while lines 414-414 and 516-516 should each catch
socket.timeout and TimeoutError as tuples, preserving the existing handler
behavior.

---

Outside diff comments:
In `@app/operation/user.py`:
- Around line 819-834: Update bulk_apply_template_to_users so its
crud_modify_user loop catches WireGuard subnet-exhaustion ValueError and
translates it through the same raise_error(..., code=400, db=...) path used by
create_user, _persist_bulk_users, and _apply_modified_user. Preserve the
existing rollback behavior for other exceptions.

In `@app/utils/wireguard.py`:
- Around line 14-36: Add a database-level unique constraint or unique index for
the WireGuard public key JSON value used by `wireguard_public_key_in_use`, and
ensure create/update persistence handles any resulting `IntegrityError`
consistently. Keep the existing application-side validation and allow users
without a public key to remain unaffected.

---

Nitpick comments:
In `@app/db/migrations/versions/3c1a7e5b9d20_add_wireguard_subnets_pool_table.py`:
- Around line 246-256: Cap the migration’s computed free offset list before
appending it to pool_rows, matching the runtime allocator’s
FREE_OFFSETS_CAP/_trim_free behavior in the wireguard CRUD path. Update the
free_offsets value in the loop over namespaces while preserving the existing
offset filtering and next_offset calculation.

In `@app/utils/wireguard.py`:
- Around line 39-42: The uncached WireGuard core lookup causes one database
query per user during bulk operations. Update app/utils/wireguard.py lines 39-42
in user_has_wireguard_access to accept or reuse precomputed wg_tags/access data,
then compute that value once and reuse it in app/operation/user.py lines 371-378
(_persist_bulk_users), 1125-1136 (_bulk_set_user_status), and 1814-1832
(bulk_apply_template_to_users); avoid rechecking for unrelated changes in
_prepare_modified_user at lines 789-813, while preserving single-user access
behavior.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: d1979161-6be9-4445-94ee-c26771f95c72

📥 Commits

Reviewing files that changed from the base of the PR and between 2700613 and 53b6a39.

📒 Files selected for processing (42)
  • .env.example
  • app/core/manager.py
  • app/db/crud/bulk.py
  • app/db/crud/user.py
  • app/db/crud/wireguard.py
  • app/db/migrations/versions/3c1a7e5b9d20_add_wireguard_subnets_pool_table.py
  • app/db/migrations/versions/a1b2c3d4e5f6_add_wireguard_settings_to_proxy_settings.py
  • app/db/models.py
  • app/models/host.py
  • app/models/reality_scan.py
  • app/models/system.py
  • app/models/user.py
  • app/operation/core.py
  • app/operation/group.py
  • app/operation/user.py
  • app/routers/system.py
  • app/routers/user.py
  • app/subscription/share.py
  • app/utils/ip_pool.py
  • app/utils/reality_scan.py
  • app/utils/wireguard.py
  • app/utils/wireguard_pool.py
  • config.py
  • dashboard/public/statics/locales/en.json
  • dashboard/public/statics/locales/fa.json
  • dashboard/public/statics/locales/ru.json
  • dashboard/public/statics/locales/zh.json
  • dashboard/src/app/router.tsx
  • dashboard/src/components/layout/sidebar.tsx
  • dashboard/src/components/layout/tabbed-route-suspense-fallback.tsx
  • dashboard/src/features/bulk/components/bulk-flow.tsx
  • dashboard/src/features/users/dialogs/user-modal.tsx
  • dashboard/src/features/users/forms/user-form.ts
  • dashboard/src/pages/_dashboard.bulk.tsx
  • dashboard/src/pages/_dashboard.bulk.wireguard.tsx
  • dashboard/src/service/api/index.ts
  • dashboard/src/utils/rbac.ts
  • tests/api/test_bulk.py
  • tests/api/test_user.py
  • tests/test_core_manager_skip_broken.py
  • tests/test_reality_scan_unit.py
  • tests/test_wireguard_alloc_unit.py
💤 Files with no reviewable changes (15)
  • app/utils/wireguard_pool.py
  • dashboard/src/pages/_dashboard.bulk.wireguard.tsx
  • app/utils/ip_pool.py
  • .env.example
  • dashboard/src/features/users/forms/user-form.ts
  • dashboard/src/components/layout/tabbed-route-suspense-fallback.tsx
  • app/db/crud/bulk.py
  • dashboard/src/app/router.tsx
  • dashboard/public/statics/locales/en.json
  • dashboard/public/statics/locales/ru.json
  • dashboard/src/components/layout/sidebar.tsx
  • app/db/migrations/versions/a1b2c3d4e5f6_add_wireguard_settings_to_proxy_settings.py
  • dashboard/public/statics/locales/zh.json
  • dashboard/src/service/api/index.ts
  • dashboard/public/statics/locales/fa.json

Comment thread app/db/crud/wireguard.py
Comment thread app/db/crud/wireguard.py Outdated
Comment thread app/utils/reality_scan.py
try:
infos = await asyncio.wait_for(loop.getaddrinfo(host, None, type=socket.SOCK_STREAM), timeout=timeout)
except (asyncio.TimeoutError, TimeoutError):
except asyncio.TimeoutError, TimeoutError:

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🔴 Critical | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Description: Verify that multiple exception types without parentheses cause a SyntaxError.
python3 -c "
try:
    pass
except ValueError, TypeError:
    pass
"

Repository: PasarGuard/panel

Length of output: 307


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Show file size and the relevant regions around each reported site.
wc -l app/utils/reality_scan.py
sed -n '160,205p' app/utils/reality_scan.py
printf '\n---\n'
sed -n '395,430p' app/utils/reality_scan.py
printf '\n---\n'
sed -n '495,530p' app/utils/reality_scan.py

# Check for Python version hints in the file and repository.
printf '\n=== version hints ===\n'
rg -n "python3|python2|#!/usr/bin/env python|from __future__|except .*," app/utils/reality_scan.py pyproject.toml setup.py requirements*.txt README* .github -g '!**/.git/**' || true

Repository: PasarGuard/panel

Length of output: 5315


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Confirm that the specific syntax pattern in Python 3 is a parse-time error,
# and compare with the parenthesized form.
python3 - <<'PY'
samples = {
    "bad": "try:\n    pass\nexcept asyncio.TimeoutError, TimeoutError:\n    pass\n",
    "good": "try:\n    pass\nexcept (asyncio.TimeoutError, TimeoutError):\n    pass\n",
}
for name, src in samples.items():
    try:
        compile(src, f"<{name}>", "exec")
        print(name, "OK")
    except SyntaxError as e:
        print(name, "SyntaxError:", e.msg)
PY

Repository: PasarGuard/panel

Length of output: 226


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the nearby context to determine whether these handlers are in a Python 3 module.
python3 - <<'PY'
from pathlib import Path
path = Path("app/utils/reality_scan.py")
text = path.read_text()
for lineno in (184, 414, 516):
    lines = text.splitlines()
    start = max(0, lineno - 5)
    end = min(len(lines), lineno + 4)
    print(f"\n--- {path}:{lineno} ---")
    for i in range(start, end):
        print(f"{i+1}: {lines[i]}")
PY

Repository: PasarGuard/panel

Length of output: 1635


🏁 Script executed:

#!/bin/bash
set -euo pipefail

# Inspect the file header and the three reported regions.
sed -n '1,40p' app/utils/reality_scan.py
printf '\n---\n'
sed -n '175,190p' app/utils/reality_scan.py
printf '\n---\n'
sed -n '408,420p' app/utils/reality_scan.py
printf '\n---\n'
sed -n '508,522p' app/utils/reality_scan.py

Repository: PasarGuard/panel

Length of output: 2844


Parenthesize these exception tuples.
except asyncio.TimeoutError, TimeoutError: and the two socket.timeout handlers are invalid Python 3 syntax and prevent app/utils/reality_scan.py from parsing. Fix all three sites:

  • app/utils/reality_scan.py#L184-L184: except (asyncio.TimeoutError, TimeoutError):
  • app/utils/reality_scan.py#L414-L414: except (socket.timeout, TimeoutError):
  • app/utils/reality_scan.py#L516-L516: except (socket.timeout, TimeoutError):
📍 Affects 1 file
  • app/utils/reality_scan.py#L184-L184 (this comment)
  • app/utils/reality_scan.py#L414-L414
  • app/utils/reality_scan.py#L516-L516
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/utils/reality_scan.py` at line 184, Parenthesize the exception tuples in
all three handlers in app/utils/reality_scan.py: lines 184-184 should catch
asyncio.TimeoutError and TimeoutError as a tuple, while lines 414-414 and
516-516 should each catch socket.timeout and TimeoutError as tuples, preserving
the existing handler behavior.

- Implemented WireGuardSubnetsList component to display usage of WireGuard subnets.
- Added a new route for WireGuard subnets in the dashboard.
- Updated RBAC to allow access to WireGuard subnets page.
Comment thread app/db/crud/wireguard.py
FREE_OFFSETS_CAP = FREE_IPS_LIMIT

IpNetwork = IPv4Network | IPv6Network
IpAddress = IPv4Address | IPv6Address

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

create a new type using type keyword

@M03ED
M03ED merged commit 3105451 into dev Jul 23, 2026
21 checks passed
@ImMohammad20000
ImMohammad20000 deleted the wg-ip-allocation-refactor branch July 24, 2026 07:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants