fix: make keypair generation async to avoid blocking the event loop
All checks were successful
CI / test (push) Successful in 1m58s
CI / release (push) Successful in 35s
CI / docker (push) Successful in 35s

generate_keypair() used synchronous subprocess.run() which blocked
the NiceGUI event loop during wg genkey/pubkey calls. This caused
WebSocket disconnects, page reloads, and the config dialog never
appearing after device creation.

Switched to asyncio.create_subprocess_exec so the event loop stays
responsive while waiting for the wg CLI.
This commit is contained in:
Stefano Bertelli 2026-03-30 22:57:00 -05:00
parent e51c53f247
commit 92554d4089
7 changed files with 31 additions and 22 deletions

View file

@ -103,7 +103,7 @@ def test_build_client_config_no_psk():
# --- Crypto (only if wg is installed) ---
def test_generate_keypair():
async def test_generate_keypair():
"""Test keypair generation — requires `wg` CLI to be installed."""
try:
subprocess.run(["wg", "--version"], capture_output=True, check=True)
@ -112,7 +112,7 @@ def test_generate_keypair():
from wiregui.utils.crypto import generate_keypair, generate_preshared_key
priv, pub = generate_keypair()
priv, pub = await generate_keypair()
assert len(priv) == 44 # base64-encoded 32 bytes
assert len(pub) == 44