Skip to content
Snippets Groups Projects
Commit aedb5003 authored by jkito's avatar jkito :skull: Committed by jkito
Browse files

ovpn: don't redeclare status variable

the status variable was being redeclared inside the
else block which goes out of scope when it returned
leading to returning the wrong status value

this fixes a bug when switching location while still
connected to a gateway as the status was always "Off"
the existing connection was not stopped before trying
to connect to the new gateway
parent a902be15
No related branches found
No related tags found
1 merge request!272ovpn: stop openvpn from management interface
Pipeline #253822 failed
......@@ -423,6 +423,9 @@ func (b *Bitmask) Reconnect() error {
if err != nil {
return err
}
log.Debug().
Str("status", status).
Msg("Status when switching location")
if status != Off {
b.statusCh <- Stopping
......@@ -451,11 +454,16 @@ func (b *Bitmask) Reconnect() error {
// GetStatus returns the VPN status
func (b *Bitmask) GetStatus() (string, error) {
status := Off
var err error
if b.isFailed() {
status = Failed
} else {
status, err := b.getOpenvpnState()
status, err = b.getOpenvpnState()
if err != nil {
log.Warn().
Err(err).
Str("status", status).
Msg("status of openvpn from management")
status = Off
}
if status == Off && b.launch.FirewallIsUp() {
......
......@@ -174,6 +174,9 @@ func (b *Bitmask) getOpenvpnState() (string, error) {
}
stateEvent, err := b.managementClient.LatestState()
if err != nil {
log.Debug().
Err(err).
Msg("error fetching latest state from management interface")
return "", err
}
status, ok := statusNames[stateEvent.NewState()]
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment