diff options
| author | JP Dillingham <jp@dillingham.me> | 2026-02-15 11:15:22 -0600 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2026-02-15 11:15:22 -0600 |
| commit | 8ab17908255a71469ce38332e2ad2b2952309ff4 (patch) | |
| tree | c1b10f5bbdb6c433742d7b04c52381c18bf12323 /src | |
| parent | 52957f1c063ef03b6f856543639c56eae035c7ba (diff) | |
| parent | e510c8a9bdd728a1c8c9429d6a88ac522a2d85b6 (diff) | |
| download | slskd-8ab17908255a71469ce38332e2ad2b2952309ff4.tar.gz | |
Merge pull request #1639 from slskd/vpn-null
Adjust some VPN service logic to make it more resilient
Diffstat (limited to 'src')
| -rw-r--r-- | src/slskd/Integrations/VPN/VPNService.cs | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/slskd/Integrations/VPN/VPNService.cs b/src/slskd/Integrations/VPN/VPNService.cs index bc3eb668..db09c041 100644 --- a/src/slskd/Integrations/VPN/VPNService.cs +++ b/src/slskd/Integrations/VPN/VPNService.cs @@ -140,7 +140,7 @@ public class VPNService : IDisposable { if (disposing) { - Timer.Dispose(); + Timer?.Dispose(); } Disposed = true; @@ -149,12 +149,20 @@ public class VPNService : IDisposable private async Task CheckConnection() { + if (Client is null) + { + throw new VPNClientException("VPN client not properly initialized; something went seriously wrong! Please report to GitHub."); + } + var options = OptionsMonitor.CurrentValue.Integration.Vpn; bool isReadyNow = false; VPNStatus status = new VPNStatus(); // one at a time! - await TimerElapsedLock.WaitAsync(0); + if (!await TimerElapsedLock.WaitAsync(0)) + { + return; + } try { @@ -162,8 +170,12 @@ public class VPNService : IDisposable try { - status = await Client.GetStatusAsync() - ?? throw new VPNClientException("VPN client returned an invalid response"); + status = await Client.GetStatusAsync(); + + if (status is null) + { + throw new VPNClientException("VPN client returned an invalid response"); + } } catch (Exception ex) { @@ -201,6 +213,9 @@ public class VPNService : IDisposable } } + // if the VPN client returned null, swap it for a default instance to prevent null refs + status ??= new VPNStatus(); + if (!IsReady && isReadyNow) { if (options.PortForwarding) |
