Skip to content

Commit 03efe8e

Browse files
committed
silence non-error and always run command to remove dummy ip
1 parent 5990ef7 commit 03efe8e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

dhcp/dhcp_windows.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"time"
88

9+
"github.com/Azure/azure-container-networking/cni/log"
910
"github.com/pkg/errors"
1011
"go.uber.org/zap"
1112
"golang.org/x/sys/windows"
@@ -98,7 +99,7 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
9899
// delete dummy ip off the interface if it already exists
99100
ret, err := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
100101
if err != nil {
101-
c.logger.Info("Could not remove dummy ip, likely because it doesn't exist", zap.String("output", ret), zap.Error(err))
102+
c.logger.Info("Could not remove dummy ip, likely because it doesn't exist", zap.String("output", ret), zap.Error(log.NewErrorWithoutStackTrace(err)))
102103
}
103104
time.Sleep(deleteIPAddressDelay)
104105

@@ -109,7 +110,9 @@ func (c *DHCP) DiscoverRequest(ctx context.Context, macAddress net.HardwareAddr,
109110
}
110111
// ensure we always remove the dummy ip we added from the interface
111112
defer func() {
112-
ret, cleanupErr := c.execClient.ExecuteCommand(ctx, "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
113+
// we always want to try to remove the dummy ip, even if the deadline was reached
114+
// so we have context.Background()
115+
ret, cleanupErr := c.execClient.ExecuteCommand(context.Background(), "netsh", "interface", "ipv4", "delete", "address", ifName, dummyIPAddressStr)
113116
if cleanupErr != nil {
114117
c.logger.Info("Failed to remove dummy ip on leaving function", zap.String("output", ret), zap.Error(err))
115118
}

0 commit comments

Comments
 (0)