[client] Fix errcheck findings from the latest golangci-lint (#8251)

This commit is contained in:
Viktor Liu
2026-10-19 22:16:59 +09:00
committed by GitHub
parent f8f335720d
commit b1f4efb160
3 changed files with 25 additions and 11 deletions
+9 -1
View File
@@ -12,6 +12,7 @@ import (
"golang.zx2c4.com/wireguard/tun/netstack" "golang.zx2c4.com/wireguard/tun/netstack"
"github.com/netbirdio/netbird/client/iface/device" "github.com/netbirdio/netbird/client/iface/device"
nbnetstack "github.com/netbirdio/netbird/client/iface/netstack"
"github.com/netbirdio/netbird/client/iface/udpmux" "github.com/netbirdio/netbird/client/iface/udpmux"
"github.com/netbirdio/netbird/client/iface/wgaddr" "github.com/netbirdio/netbird/client/iface/wgaddr"
"github.com/netbirdio/netbird/client/iface/wgproxy" "github.com/netbirdio/netbird/client/iface/wgproxy"
@@ -62,6 +63,10 @@ func (fakeProxyFactory) Free() error { return nil }
// WGIface.GetDevice() which needs the same mutex. The fix is to drop // WGIface.GetDevice() which needs the same mutex. The fix is to drop
// the lock before tun.Close() returns control. // the lock before tun.Close() returns control.
func TestWGIface_CloseReleasesMutexBeforeTunClose(t *testing.T) { func TestWGIface_CloseReleasesMutexBeforeTunClose(t *testing.T) {
// Netstack mode skips the platform interface cleanup in Close, so only
// the mutex and tun close behavior is exercised.
t.Setenv(nbnetstack.EnvUseNetstackMode, "true")
tun := &fakeTunDevice{ tun := &fakeTunDevice{
closeStarted: make(chan struct{}), closeStarted: make(chan struct{}),
unblockClose: make(chan struct{}), unblockClose: make(chan struct{}),
@@ -105,7 +110,10 @@ func TestWGIface_CloseReleasesMutexBeforeTunClose(t *testing.T) {
close(tun.unblockClose) close(tun.unblockClose)
select { select {
case <-closeDone: case err := <-closeDone:
if err != nil {
t.Errorf("WGIface.Close() returned an error: %v", err)
}
case <-time.After(2 * time.Second): case <-time.After(2 * time.Second):
t.Fatal("WGIface.Close() never returned after the tun was unblocked") t.Fatal("WGIface.Close() never returned after the tun was unblocked")
} }
+4 -2
View File
@@ -166,7 +166,8 @@ func (c *Client) ExecuteCommandWithIO(ctx context.Context, command string) error
case <-ctx.Done(): case <-ctx.Done():
_ = session.Signal(ssh.SIGTERM) _ = session.Signal(ssh.SIGTERM)
select { select {
case <-done: case err := <-done:
log.Debugf("session ended after SIGTERM: %v", err)
return ctx.Err() return ctx.Err()
case <-time.After(100 * time.Millisecond): case <-time.After(100 * time.Millisecond):
return ctx.Err() return ctx.Err()
@@ -205,7 +206,8 @@ func (c *Client) ExecuteCommandWithPTY(ctx context.Context, command string) erro
case <-ctx.Done(): case <-ctx.Done():
_ = session.Signal(ssh.SIGTERM) _ = session.Signal(ssh.SIGTERM)
select { select {
case <-done: case err := <-done:
log.Debugf("session ended after SIGTERM: %v", err)
return ctx.Err() return ctx.Err()
case <-time.After(100 * time.Millisecond): case <-time.After(100 * time.Millisecond):
return ctx.Err() return ctx.Err()
+5 -1
View File
@@ -335,7 +335,11 @@ func (s *BaseServer) Stop() error {
} }
select { select {
case <-s.Errors(): case err := <-s.Errors():
if err != nil {
log.WithContext(ctx).Infof("stopped Management Service: %v", err)
return nil
}
log.WithContext(ctx).Infof("stopped Management Service") log.WithContext(ctx).Infof("stopped Management Service")
return nil return nil
case <-ctx.Done(): case <-ctx.Done():