← Hydra Torrent

Testing a torrent client's VPN kill switch at the socket level

Hydra Torrent · November 2026 · measured on Linux with a real WireGuard tunnel

A common way to build a kill switch is a check: every few seconds, see whether the VPN is up, and if it isn't, pause everything. That is a flag. Anything that runs before the check notices, and any code path that forgets to look at the flag (a torrent added during the outage, a resume after a restart, DHT), sends traffic out of your real connection.

For Hydra I wanted a kill switch that fails closed by construction, and then I wanted to measure it instead of trusting the status badge. The measurement turned up a leak, which is the most useful part of this post.

Bind, don't check

libtorrent lets you choose the local address its sockets listen on and send from (listen_interfaces and outgoing_interfaces). Hydra sets both to the VPN interface's own address, for example 10.157.3.153 on wg0.

When the tunnel goes down, that interface and its address disappear. A socket bound to an address that no longer exists on any interface cannot send anything: the kernel has no route for it. There is no fallback to the default route, because the session was never allowed to use it.

That covers the gap between the tunnel dying and Hydra noticing. Once its VPN monitor does notice, it rebinds the whole session to loopback (127.0.0.1), which cannot reach a single peer, and marks every transfer "Waiting for VPN". When the VPN comes back, even on a new address, it rebinds to the new VPN address and resumes. The pause is for the UI. The binding is what does the protecting.

The test

The box is a Proxmox LXC running Hydra next to a real Plex server, with a PIA WireGuard tunnel brought up by wg-quick and policy routing that sends traffic from the VPN address into the tunnel. The test downloads a Debian netinst ISO, drops the tunnel with wg-quick down wg0, and every half second lists every TCP and UDP socket the Hydra process owns (ss -tunpa, filtered to its PID). A socket counts as a leak if its local address is anything other than the VPN address or loopback (the web UI on port 8765 is excluded). Eight seconds into the outage it adds a second torrent by URL. Then it brings the tunnel back and times the recovery.

[  6.2s] BEFORE: Downloading 1.1MB/s | sockets 58, on VPN 2, leaks 0
[  6.2s] >>> wg-quick down wg0 (tunnel dropped)
[  7.0s] down  0.5s: sockets 56, leaks 0
[ 10.2s] down  3.8s: Downloading 0.0MB/s | sockets 39, leaks 0
[ 13.4s] down  7.0s: sockets 1, leaks 0
[ 14.5s] added a NEW torrent while the VPN is down
[ 28.0s] OUTAGE SUMMARY: max leaking sockets seen = 0
[ 28.0s] >>> wg-quick up wg0 (tunnel restored)
[ 44.3s] RESUMED after 16s: Downloading 0.5MB/s | on VPN 3, leaks 0

("on VPN" counts established connections. The other sockets before the drop were connection attempts to peers, also bound to the VPN address; "leaks" counts anything bound elsewhere.)

The sockets still open during the outage were all harmless by construction:

tcp LISTEN    127.0.0.1%lo:6001
udp UNCONN    127.0.0.1%lo:6001
tcp SYN-SENT  10.157.3.153%if212:56929 -> 130.239.18.158:6969
tcp SYN-SENT  127.0.0.1%lo:49873       -> 130.239.18.158:6969

A tracker announce stuck in SYN-SENT on the vanished VPN address, another one on loopback, and the listener rebound to loopback. None of them can put a packet on the real interface. The 56 peer sockets still bound to the dead VPN address drained to zero within seven seconds as they timed out, without ever being able to send.

The leak the test found

The first run of this test did not come out clean. When it added the second torrent during the outage, a new socket appeared:

tcp ESTAB [2403:5807:...]:37292 -> [2001:6b0:19::173]:443

That is the Hydra process talking HTTPS to cdimage.debian.org from the home connection's real IPv6 address. Not BitTorrent traffic: it was downloading the .torrent file itself. Hydra fetched .torrent links with a plain requests.get, which follows the default route. The VPN's policy routing only covers traffic sent from the VPN address, so an unbound request goes straight out the real interface, VPN up or down. On the same box, a plain request to an IP-echo service returned the home IPv6 address while the tunnel was up.

So every torrent added by URL (a search result whose link redirects to a public tracker, an Auto-DL release without a magnet, a pasted link) showed the host of that URL your real address. The swarm never saw it, but the tracker's website did.

The fix, in v1.4.35, decides per URL:

HostVPNKill switchFetch
LAN or this machine (Jackett)anyanydirect (the tunnel can't reach the LAN, and nothing leaves home)
publicupanybound to the VPN address (which also rules out IPv6)
publicdownonrefused
publicdownoffdirect (you chose to run without a VPN)

Every redirect hop is checked again. After the fix the same IP-echo request exits as the PIA address, and in the repeat run above the add during the outage was refused with "VPN is down and the kill switch is on - not fetching cdimage.debian.org over your real connection".

The lesson I took from it: a kill switch for "the torrent client" has to cover every request the client makes, not just the BitTorrent sockets. Binding libtorrent was the easy part. The leak was in an ordinary HTTP call nobody thinks of as torrent traffic.

What this does not cover

Try it

Hydra Torrent is a BitTorrent client for people who run Plex or Jellyfin: search through your own Jackett, download, and finished files are filed into your library with a library scan, kill switch included. MIT licensed, Docker (x86-64 and ARM64), Linux or Windows.

Website · Source on GitHub · Changelog (every bug, with its cause)