diff --git a/multicast/discovery_test.go b/multicast/discovery_test.go index 30e2830b1..25f539a0b 100644 --- a/multicast/discovery_test.go +++ b/multicast/discovery_test.go @@ -103,8 +103,9 @@ func (m *multicastSuite) Test_Lookup() { testDiscovery := NewDiscovery(c.lookupIface, c.lookupPort) ctx := context.Background() + var cancel context.CancelFunc if c.lookupTimeout > 0 { - ctx, _ = context.WithTimeoutCause(ctx, c.lookupTimeout, fmt.Errorf("Timeout exceeded")) + ctx, cancel = context.WithTimeoutCause(ctx, c.lookupTimeout, fmt.Errorf("Timeout exceeded")) } receivedInfo, err := testDiscovery.Lookup(ctx, c.lookupVersion) @@ -116,6 +117,11 @@ func (m *multicastSuite) Test_Lookup() { m.Require().Equal(c.lookupErr.Error(), err.Error()) } + // Cancel the timeout to avoid leaking the context. + if cancel != nil { + cancel() + } + // Stop the responder. err = discovery.StopResponder() m.Require().NoError(err)