Skip to content

Commit

Permalink
added a fix for the example server crashing when NGINX is not running…
Browse files Browse the repository at this point in the history
…. Removed the waitgroup in comms.go Close, as if no active waitgroup can cause a negative count. (#17)

Co-authored-by: o.omahony <[email protected]>
  • Loading branch information
oliveromahony and o.omahony authored Aug 22, 2022
1 parent baf3723 commit 855e28d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
12 changes: 10 additions & 2 deletions sdk/examples/services/command_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,10 @@ func (grpcService *CommandGrpcService) handleCommand(cmd *proto.Command) {
case *proto.Command_AgentConnectRequest:
log.Infof("Got agentConnectRequest from Agent %v", commandData)
grpcService.registrationData = commandData.AgentConnectRequest
grpcService.nginxes = commandData.AgentConnectRequest.Details
if (commandData.AgentConnectRequest != nil && len(commandData.AgentConnectRequest.Details) > 0) {
grpcService.nginxes = commandData.AgentConnectRequest.Details
}

// Step 2: Send AgentConnectResponse to Agent
grpcService.sendAgentConnectResponse(cmd)
case *proto.Command_NginxConfig:
Expand Down Expand Up @@ -187,6 +190,11 @@ func (grpcService *CommandGrpcService) GetConfigs() *proto.NginxConfig {
}

func (grpcService *CommandGrpcService) sendAgentConnectResponse(cmd *proto.Command) {
// get first nginx id for example
nginxId := "0"
if len(cmd.GetAgentConnectRequest().GetDetails()) > 0 {
nginxId = cmd.GetAgentConnectRequest().GetDetails()[0].GetNginxId()
}
response := &proto.Command{
Data: &proto.Command_AgentConnectResponse{
AgentConnectResponse: &proto.AgentConnectResponse{
Expand All @@ -197,7 +205,7 @@ func (grpcService *CommandGrpcService) sendAgentConnectResponse(cmd *proto.Comma
{
Checksum: "",
// only one nginx id in this example
NginxId: cmd.GetAgentConnectRequest().GetDetails()[0].GetNginxId(),
NginxId: nginxId,
SystemId: cmd.GetAgentConnectRequest().GetMeta().GetSystemUid(),
},
},
Expand Down
1 change: 0 additions & 1 deletion src/plugins/comms.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ func (r *Comms) Close() {
log.Info("Comms is wrapping up")
r.started.Store(false)
r.readyToSend.Store(false)
r.wait.Done()
}

func (r *Comms) Info() *core.Info {
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 855e28d

Please sign in to comment.