From 31e472baa4d8ffa7396e8f376cbfb60c4410a58e Mon Sep 17 00:00:00 2001 From: Michael Yang Date: Fri, 28 Feb 2025 13:47:45 -0800 Subject: [PATCH] runner: defer context cancel defer the cancel to guarantee it runs --- runner/llamarunner/runner.go | 4 ++-- runner/ollamarunner/runner.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/runner/llamarunner/runner.go b/runner/llamarunner/runner.go index 1afc793ef..82880c980 100644 --- a/runner/llamarunner/runner.go +++ b/runner/llamarunner/runner.go @@ -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 } diff --git a/runner/ollamarunner/runner.go b/runner/ollamarunner/runner.go index 6b4c7be07..db9b271e5 100644 --- a/runner/ollamarunner/runner.go +++ b/runner/ollamarunner/runner.go @@ -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 }