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.
This commit is contained in:
Mikhail Bragin 2022-03-13 15:16:16 +01:00 committed by GitHub
parent a3a6283ac6
commit d7b69b91b9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 2 deletions

View File

@ -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
}

View File

@ -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
}
}()