Repository navigation
Description
VPNConnector._get_current_connection() does:
if protocol := self._registry.get(persisted_parameters.protocol):which expects None when there's no valid implementation, as the Registry.get() docstring says. But Registry.get() raises RuntimeError instead (proton/vpn/core/registry.py:116), so VPNConnector.get() / initialize_state() blows up and the client can't create the connector at all.
This happens whenever connection_persistence.json points to a protocol whose validate() returns False on the next start. For example, a protun-* connection (these are now forced for free users) and then running the app where protun isn't valid (snap/flatpak, older NM, missing platform module). The file stays there, so every start fails the same way.
Steps to reproduce
- Connect with
protun-smartand kill the app, soconnection_persistence.jsonstays. - Start the app in an environment where
ProTun.validate()returns False.
With the real registry and NetworkManager:
registered: ['openvpn-udp', 'openvpn-tcp', 'wireguard', 'protun-udp', 'protun-tcp', 'protun-tls', 'protun-smart']
valid: ['wireguard', 'openvpn-udp', 'openvpn-tcp']
initialize_state -> RuntimeError: No valid implementation found for protun-smart
Expected
Initial state is Disconnected, as for any persisted connection that can't be restored.
Possible fix
Either make Registry.get() return None as documented, or catch the RuntimeError in _get_current_connection().
Found on master @ 1b6dcda (proton-vpn-api-core 5.8.7), Ubuntu 24.04, Python 3.12, NetworkManager 1.46.0.
Test (fails on current master)
import tempfile
from unittest.mock import Mock
import pytest
from proton.vpn.connection import states
from proton.vpn.connection.interfaces import ProtocolPorts, VPNServer
from proton.vpn.connection.persistence import ConnectionParameters, ConnectionPersistence
from proton.vpn.core.registry import Registry
from proton.vpn.core.vpnconnector import VPNConnector
@pytest.mark.asyncio
async def test_initial_state_is_disconnected_when_persisted_protocol_is_not_available():
persistence = ConnectionPersistence(tempfile.mkdtemp())
persistence.save(ConnectionParameters(
connection_id="f3c1e0a0-0000-0000-0000-000000000000",
backend="linuxnetworkmanager",
protocol="protun-smart",
server=VPNServer(
server_ip="1.1.1.1",
openvpn_ports=ProtocolPorts([1194], [443], []),
wireguard_ports=ProtocolPorts([51820], [443], []),
domain="node.protonvpn.net", x25519pk="key",
server_id="id", server_name="CH#1", has_ipv6_support=False
)
))
unavailable = Mock()
unavailable.get_key.return_value = "protun-smart"
unavailable.validate.return_value = False # e.g. running inside flatpak/snap
registry = Registry()
registry.register(unavailable)
session_holder = Mock()
session_holder.session.logged_in = True
connector = VPNConnector(
session_holder, Mock(), Mock(), registry,
connection_persistence=persistence,
publisher=Mock(), port_forward_file_handler=Mock()
)
state = await connector._get_initial_state()
assert isinstance(state, states.Disconnected)
Activity
Miixms99 commentedon Nov 16, 2026
I've opened a fix for this in #43.
Problem
On startup,
VPNConnector.initialize_state()calls_get_current_connection(), which restores the last connection fromconnection_persistence.json. That method usesif protocol := self._registry.get(...), so it expectsNonewhen the persisted protocol has no valid implementation. ButRegistry.get()inproton/vpn/core/registry.pyraisesRuntimeErrorinstead. The result: if the persisted protocol is no longer registered, or is registered but itsvalidate()now returns false (for example a leftoverprotun-smartconnection in a snap/flatpak build or on an older NetworkManager), the whole connector crashes during initialisation instead of starting asDisconnected.Reproduce
connection_persistence.jsonpointing at a protocol such asprotun-smart.validate()returns false.RuntimeError: No valid implementation found for protun-smartinstead of reaching theDisconnectedstate.Fix
#43 catches that
RuntimeErrorin_get_current_connection(), logs a warning naming the protocol, and returnsNone, so startup continues asDisconnected. This matches how a missing or corrupt persistence file is already handled, and the file is left on disk, as on the corrupt-file path.Registry.get()itself is unchanged, becauseconnect()and the protun default selection rely on it raising.Checks
New regression test
tests/python/core/test_vpnconnector_persistence.py, with stubRegistryclasses (no real VPN is opened), covering five paths:validate()returns falsewireguardconnection (still restored, no warning)Results on Linux, Python 3.12.3, pytest 9.2.0:
stable:2 failed, 3 passed; both failures areRuntimeError: No valid implementation found for protun-smart5 passedtest_modules_exist(No module named proton.vpn.platform.protun), because the protun module can't be built outside Proton's tree; it fails onstabletoo and is unrelated to this changeflake8on the changed files is clean, and pylint shows no new messages compared withstableFull commands and output are in the PR description. AI assistance was used to write the change and run the tests; this is disclosed in the PR.