runner: defer context cancel

defer the cancel to guarantee it runs
This commit is contained in:
Michael Yang 2025-02-28 13:47:45 -08:00
parent 657685e85d
commit 31e472baa4
2 changed files with 4 additions and 4 deletions

View File

@ -968,13 +968,14 @@ func Execute(args []string) error {
server.cond = sync.NewCond(&server.mu)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go server.run(ctx)
addr := "127.0.0.1:" + strconv.Itoa(*port)
listener, err := net.Listen("tcp", addr)
if err != nil {
fmt.Println("Listen error:", err)
cancel()
return err
}
defer listener.Close()
@ -994,6 +995,5 @@ func Execute(args []string) error {
return err
}
cancel()
return nil
}

View File

@ -890,13 +890,14 @@ func Execute(args []string) error {
server.cond = sync.NewCond(&server.mu)
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
go server.run(ctx)
addr := "127.0.0.1:" + strconv.Itoa(*port)
listener, err := net.Listen("tcp", addr)
if err != nil {
fmt.Println("Listen error:", err)
cancel()
return err
}
defer listener.Close()
@ -916,6 +917,5 @@ func Execute(args []string) error {
return err
}
cancel()
return nil
}