Skip to content

Commit

Permalink
fix: forget 2 waiting till the ctx done.
Browse files Browse the repository at this point in the history
  • Loading branch information
anrs committed May 21, 2023
1 parent bcff0f7 commit d8488b4
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions internal/server/grpc/grpc_app.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"encoding/json"
"fmt"
"io"
"sync"

pb "github.com/projecteru2/libyavirt/grpc/gen"
"github.com/projecteru2/libyavirt/types"
Expand Down Expand Up @@ -84,7 +85,12 @@ func (y *GRPCYavirtd) Events(_ *pb.EventsOptions, server pb.YavirtdRPC_EventsSer
return err
}

var wg sync.WaitGroup
defer wg.Wait()

wg.Add(1)
go func() {
defer wg.Done()
defer log.Infof("[grpcserver] events goroutine has done")
defer watcher.Stop()

Expand All @@ -98,9 +104,11 @@ func (y *GRPCYavirtd) Events(_ *pb.EventsOptions, server pb.YavirtdRPC_EventsSer

case <-watcher.Done():
// The watcher already has been stopped.
log.Infof("[grpcserver] watcher has done")
return

case <-ctx.Done():
log.Infof("[grpcserver] ctx done")
return
}
}
Expand Down

0 comments on commit d8488b4

Please sign in to comment.