Do not try to close connection if it is not opened in VPNTCPCheck()

This commit is contained in:
eleksir
2024-09-13 22:02:28 +03:00
parent 0fd5ed87a2
commit 1485354b6c

11
vpn.go
View File

@@ -64,8 +64,6 @@ func UpdateVPNStatus() {
// VPNTCPCheck intended to check arbitrary service inside vpn segment, to indicate that openvpn sevice not stoned. // VPNTCPCheck intended to check arbitrary service inside vpn segment, to indicate that openvpn sevice not stoned.
func VPNTCPCheck() bool { func VPNTCPCheck() bool {
var status bool
conn, err := net.DialTimeout( conn, err := net.DialTimeout(
"tcp", "tcp",
fmt.Sprintf("%s:%d", Conf.Vpn.TCPCheck.Host, Conf.Vpn.TCPCheck.Port), fmt.Sprintf("%s:%d", Conf.Vpn.TCPCheck.Host, Conf.Vpn.TCPCheck.Port),
@@ -73,14 +71,11 @@ func VPNTCPCheck() bool {
) )
if err == nil { if err == nil {
status = true _ = conn.Close()
} else { return true
status = false
} }
_ = conn.Close() return false
return status
} }
// VPNFileCheck checks modification time of openvpn-status file. // VPNFileCheck checks modification time of openvpn-status file.