Skip to content

Commit c73790d

Browse files
feedback
Signed-off-by: Adrian Cole <[email protected]>
1 parent 5bdc082 commit c73790d

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

internal/infrastructure/host/proxy_infra.go

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"path/filepath"
1313
"regexp"
1414
"strings"
15+
"sync"
1516

1617
func_e "github.com/tetratelabs/func-e"
1718
"github.com/tetratelabs/func-e/api"
@@ -34,16 +35,19 @@ type proxyContext struct {
3435

3536
// Close implements the Manager interface.
3637
func (i *Infra) Close() error {
37-
// Collect all proxy names first to avoid holding locks during stopEnvoy calls
38-
var names []string
39-
i.proxyContextMap.Range(func(key, value interface{}) bool {
40-
names = append(names, key.(string))
38+
var wg sync.WaitGroup
39+
40+
// Stop any Envoy subprocesses in parallel
41+
i.proxyContextMap.Range(func(key, value any) bool {
42+
wg.Add(1)
43+
go func(name string) {
44+
defer wg.Done()
45+
i.stopEnvoy(name)
46+
}(key.(string))
4147
return true
4248
})
4349

44-
for _, name := range names {
45-
i.stopEnvoy(name)
46-
}
50+
wg.Wait()
4751
return nil
4852
}
4953

internal/infrastructure/host/proxy_infra_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"io"
1212
"path"
1313
"testing"
14+
"testing/synctest"
1415
"time"
1516

1617
"github.com/stretchr/testify/require"
@@ -155,9 +156,11 @@ func TestInfra_Close(t *testing.T) {
155156
})
156157
require.Equal(t, 3, count, "expected 3 proxies to be running")
157158

158-
// Close should stop all proxies
159-
err = i.Close()
160-
require.NoError(t, err)
159+
// Close should stop all proxies and not leak goroutines
160+
synctest.Test(t, func(t *testing.T) {
161+
err := i.Close()
162+
require.NoError(t, err)
163+
})
161164

162165
// Verify all proxies are stopped
163166
count = 0

0 commit comments

Comments
 (0)