diff --git a/cmd/sharded-test-server/cache.go b/cmd/sharded-test-server/cache.go index 6bcfa9764e6..fb79e0a8d00 100644 --- a/cmd/sharded-test-server/cache.go +++ b/cmd/sharded-test-server/cache.go @@ -73,6 +73,13 @@ func startCacheServer(ctx context.Context, logDirPath, workingDir string, synthe return nil, "", err } + defer func() { + err = logFile.Close() + if err != nil { + klog.ErrorS(err, "failed to close the log file") + } + }() + writer := helpers.NewHeadWriter(logFile, out) cmd.Stdout = writer cmd.Stdin = os.Stdin diff --git a/cmd/sharded-test-server/frontproxy.go b/cmd/sharded-test-server/frontproxy.go index 95187a90c8c..9029776c507 100644 --- a/cmd/sharded-test-server/frontproxy.go +++ b/cmd/sharded-test-server/frontproxy.go @@ -157,6 +157,13 @@ func startFrontProxy( return err } + defer func() { + err = logFile.Close() + if err != nil { + klog.ErrorS(err, "failed to close the log file") + } + }() + writer := helpers.NewHeadWriter(logFile, out) cmd.Stdout = writer cmd.Stdin = os.Stdin diff --git a/cmd/sharded-test-server/virtual.go b/cmd/sharded-test-server/virtual.go index bb97453128e..ad442fab0f2 100644 --- a/cmd/sharded-test-server/virtual.go +++ b/cmd/sharded-test-server/virtual.go @@ -209,6 +209,13 @@ func (v *VirtualWorkspace) start(ctx context.Context) error { return err } + defer func() { + err = logFile.Close() + if err != nil { + klog.ErrorS(err, "failed to close the log file") + } + }() + v.writer = helpers.NewHeadWriter(logFile, out) cmd.Stdout = v.writer cmd.Stdin = os.Stdin diff --git a/cmd/test-server/kcp/shard.go b/cmd/test-server/kcp/shard.go index 9ec42dfbdb8..d15e753661a 100644 --- a/cmd/test-server/kcp/shard.go +++ b/cmd/test-server/kcp/shard.go @@ -117,6 +117,13 @@ func (s *Shard) Start(ctx context.Context, quiet bool) error { return err } + defer func() { + err = logFile.Close() + if err != nil { + klog.ErrorS(err, "failed to close the log file") + } + }() + s.writer = helpers.NewHeadWriter(logFile, out) cmd.Stdout = s.writer cmd.Stdin = os.Stdin