Skip to content

Commit

Permalink
Make Execute() wait for initialization of status gRPC server before use
Browse files Browse the repository at this point in the history
  • Loading branch information
yvanoers committed Feb 22, 2021
1 parent da8fbdf commit e5c3558
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugin/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,21 +48,33 @@ func (m *ExecutorClient) Execute(args *types.ExecuteRequest, cb StatusHelper) (*
// This is where the magic conversion to Proto happens
statusHelperServer := &GRPCStatusHelperServer{Impl: cb}

initChan := make(chan bool, 1)
var s *grpc.Server
serverFunc := func(opts []grpc.ServerOption) *grpc.Server {
s = grpc.NewServer(opts...)
types.RegisterStatusHelperServer(s, statusHelperServer)
initChan <- true

return s
}

brokerID := m.broker.NextId()
go m.broker.AcceptAndServe(brokerID, serverFunc)
go func() {
m.broker.AcceptAndServe(brokerID, serverFunc)
// AcceptAndServe might terminate without calling serverFunc
// To prevent eternal blocking, send 'init done' signal
initChan <- true
}()

// Wait for s to be initialized in the goroutine
<-initChan

args.StatusServer = brokerID
r, err := m.client.Execute(context.Background(), args)

s.Stop()
if s != nil {
s.Stop()
}
return r, err
}

Expand Down

0 comments on commit e5c3558

Please sign in to comment.