From 30e8ca2b214e953a4af8d00ddbf349d25ead495e Mon Sep 17 00:00:00 2001 From: go_vargo <44902466+govargo@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:06:45 +0900 Subject: [PATCH] Fix goroutine leak in game frontend (#47) * Fix with goimport -w * Fix go routine leak --- frontend/frontend.go | 9 +++++++-- game/pb/messages.pb.go | 5 +++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/frontend/frontend.go b/frontend/frontend.go index 2870e4ed..e600aa1b 100644 --- a/frontend/frontend.go +++ b/frontend/frontend.go @@ -119,14 +119,19 @@ func streamAssignments(ctx context.Context, assignments chan *pb.Assignment, err errs <- fmt.Errorf("error getting assignment stream: %w", err) return } - for { + + var assignment *pb.Assignment + for assignment.GetConnection() == "" { resp, err := stream.Recv() if err != nil { errs <- fmt.Errorf("error streaming assignment: %w", err) return } - assignments <- resp.Assignment + assignment = resp.Assignment } + + assignments <- assignment + log.Printf("Got assignment: %v", assignment) } func connectFrontendServer() (*grpc.ClientConn, error) { diff --git a/game/pb/messages.pb.go b/game/pb/messages.pb.go index 4a24cfd9..888e5c42 100644 --- a/game/pb/messages.pb.go +++ b/game/pb/messages.pb.go @@ -21,10 +21,11 @@ package pb import ( - protoreflect "google.golang.org/protobuf/reflect/protoreflect" - protoimpl "google.golang.org/protobuf/runtime/protoimpl" reflect "reflect" sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" ) const (