Skip to content

Commit 133daa0

Browse files
committed
fix(apps-proxy): eliminate port race in TestKaiPreviewSlidingRefresh
Replace GetFreePort()+Listen() with a direct Listen("127.0.0.1:0") so the OS assigns a free port atomically, removing the TOCTOU window where a parallel test could steal the port between the two calls.
1 parent e36805a commit 133daa0

1 file changed

Lines changed: 3 additions & 3 deletions

File tree

internal/pkg/service/appsproxy/proxy/proxy_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3219,10 +3219,10 @@ func TestKaiPreviewSlidingRefresh(t *testing.T) {
32193219
logger.SetErrOutput(loggerWriter)
32203220
handler := proxy.NewHandler(ctx, d)
32213221

3222-
// Boot a TLS proxy server.
3223-
port := pm.GetFreePort()
3222+
// Boot a TLS proxy server. Bind to :0 to let the OS assign a free port atomically,
3223+
// eliminating the TOCTOU race that occurs when GetFreePort() releases the port before Listen().
32243224
var lc net.ListenConfig
3225-
l, err := lc.Listen(ctx, "tcp", fmt.Sprintf("127.0.0.1:%d", port))
3225+
l, err := lc.Listen(ctx, "tcp", "127.0.0.1:0")
32263226
require.NoError(t, err)
32273227
proxySrv := &httptest.Server{
32283228
Listener: l,

0 commit comments

Comments
 (0)