Skip to content

Commit

Permalink
history: shutdown signal should kill the shell
Browse files Browse the repository at this point in the history
  • Loading branch information
joshi4 committed Jun 2, 2024
1 parent b28bec0 commit 252c368
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions cmd/history.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,22 @@ func recordHistory(cmd *cobra.Command, _ []string) {
commandProcessedChan <- true
}

ctx, cancelCtx := context.WithCancel(ctx)
defer cancelCtx()

ss, err := server.NewUnixSocketServerWithDefaultPath(server.WithCommandRecordedHook(hook))
if errors.Is(err, server.ErrAbortRecording) {
display.Info("Recording aborted")
return
}
defer ss.Close()

go func() {
ss.ListenAndServe()
// kill b/g shell if we exit early
cancelCtx()
os.Exit(1)
}()

if err != nil {
display.FatalErrWithSupportCTA(err)
Expand Down Expand Up @@ -178,14 +189,6 @@ func expandHistory(ctx context.Context,
ctx, cancelCtx := context.WithCancel(ctx)
defer cancelCtx()

go func() {
srv.ListenAndServe()
// kill b/g shell if we exit early
cancelCtx()
}()

defer srv.Close()

c, err := sh.SpawnHistoryExpander(ctx)
if err != nil {
err := fmt.Errorf("failed to start history recording: %w", err)
Expand Down

0 comments on commit 252c368

Please sign in to comment.