Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion internal/execute/tsc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package execute
import (
"context"
"fmt"
"os"
"os/signal"
"strings"
"syscall"

"github.com/microsoft/typescript-go/internal/ast"
"github.com/microsoft/typescript-go/internal/collections"
Expand Down Expand Up @@ -107,7 +110,18 @@ func tscCompilation(sys tsc.System, commandLine *tsoptions.ParsedCommandLine, te
if pprofDir := commandLine.CompilerOptions().PprofDir; pprofDir != "" {
// !!! stderr?
profileSession := pprof.BeginProfiling(pprofDir, sys.Writer())
defer profileSession.Stop()

if commandLine.CompilerOptions().Watch.IsTrue() {
go func() {
ctx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
defer stop()
<-ctx.Done()
profileSession.Stop()
os.Exit(int(tsc.ExitStatusSuccess))
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Calling os.Exit() from a goroutine bypasses deferred cleanup functions in the main goroutine and can lead to incomplete cleanup. Consider using a channel or context cancellation to signal the main goroutine to exit gracefully instead.

Copilot uses AI. Check for mistakes.
}()
Copy link

Copilot AI Dec 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When watch mode is disabled, the profiling session is never stopped because the defer profileSession.Stop() was removed. The defer statement should be preserved and only skipped when watch mode is enabled. Consider adding else { defer profileSession.Stop() } after the watch mode block.

Suggested change
}()
}()
} else {
defer profileSession.Stop()

Copilot uses AI. Check for mistakes.
} else {
defer profileSession.Stop()
}
}

if commandLine.CompilerOptions().Init.IsTrue() {
Expand Down
Loading