From d7b69b91b9e492ee8900880d05bbd76bcfbb73d6 Mon Sep 17 00:00:00 2001 From: Mikhail Bragin Date: Sun, 13 Mar 2022 15:16:16 +0100 Subject: [PATCH] Fix error when removing peer conn (#264) When stopping engine, all peer conns have to be closed and for each peer WireGuard iface is called to remove WireGuard peer. This operation happens in a goroutine causing Engine to remove the whole WireGuard interface before. Therefore consequent calls to RemovePeer are unsuccessful. This fix just adds a small delay before removing interface. --- client/internal/engine.go | 6 +++++- client/internal/peer/conn.go | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/client/internal/engine.go b/client/internal/engine.go index 8f0fb7c84..f084f491c 100644 --- a/client/internal/engine.go +++ b/client/internal/engine.go @@ -123,6 +123,10 @@ func (e *Engine) Stop() error { return err } + // very ugly but we want to remove peers from the WireGuard interface first before removing interface. + // Removing peers happens in the conn.CLose() asynchronously + time.Sleep(500 * time.Millisecond) + log.Debugf("removing Wiretrustee interface %s", e.config.WgIfaceName) if e.wgInterface.Interface != nil { err = e.wgInterface.Close() @@ -489,7 +493,7 @@ func (e Engine) connWorker(conn *peer.Conn, peerKey string) { // if peer has been removed -> give up if !e.peerExists(peerKey) { - log.Infof("peer %s doesn't exist anymore, won't retry connection", peerKey) + log.Debugf("peer %s doesn't exist anymore, won't retry connection", peerKey) return } diff --git a/client/internal/peer/conn.go b/client/internal/peer/conn.go index f75a612f5..83b4904d6 100644 --- a/client/internal/peer/conn.go +++ b/client/internal/peer/conn.go @@ -153,7 +153,7 @@ func (conn *Conn) Open() error { defer func() { err := conn.cleanup() if err != nil { - log.Errorf("error while cleaning up peer connection %s: %v", conn.config.Key, err) + log.Warnf("error while cleaning up peer connection %s: %v", conn.config.Key, err) return } }()