Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix race on shutdown #666

Merged
merged 1 commit into from
May 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/service/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ func (p *Process) Gather() ([]*dto.MetricFamily, error) {
// Get the metrics from the handler via IPC
metricsResponse, err := p.ipcHandlerClient.GetMetrics(context.Background(), &ipc.MetricsRequest{})
if err != nil {
logger.Warnw("failed to obtain metrics from handler", err, "egress_id", p.req.EgressId)
logger.Warnw("failed to obtain metrics from handler", err, "egressID", p.req.EgressId)
return make([]*dto.MetricFamily, 0), nil // don't return an error, just skip this handler
}

Expand Down
14 changes: 11 additions & 3 deletions pkg/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,9 +203,17 @@ func (s *Service) killProcess(egressID string, maxUsage float64) {
}

func (s *Service) Close() {
for s.GetRequestCount() > 0 {
for {
s.mu.RLock()
isIdle := len(s.activeHandlers) == 0
s.mu.RUnlock()

if isIdle {
logger.Infow("closing server")
s.psrpcServer.Shutdown()
return
}

time.Sleep(time.Second)
}
logger.Infow("closing server")
s.psrpcServer.Shutdown()
}
1 change: 1 addition & 0 deletions pkg/service/service_rpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ func (s *Service) AddHandler(egressID string, p *Process) error {
}()

case <-time.After(10 * time.Second):
logger.Warnw("no response from handler", nil, "egressID", egressID)
_ = p.cmd.Process.Kill()
s.processEnded(p, errors.ErrEgressNotFound)
}
Expand Down
Loading