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

adds logging to desktop runner around checking if process exists #1227

Merged
merged 2 commits into from
Jun 12, 2023
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
19 changes: 16 additions & 3 deletions ee/desktop/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ func (r *DesktopUsersProcessesRunner) killDesktopProcesses() {
case <-time.After(r.interruptTimeout):
level.Error(r.logger).Log("msg", "timeout waiting for desktop processes to exit, now killing")
for uid, processRecord := range r.uidProcs {
if !processExists(processRecord) {
if !r.processExists(processRecord) {
continue
}
if err := processRecord.process.Kill(); err != nil {
Expand Down Expand Up @@ -580,7 +580,7 @@ func (r *DesktopUsersProcessesRunner) userHasDesktopProcess(uid string) bool {
}

// have a record of process, but it died for some reason, log it
if !processExists(proc) {
if !r.processExists(proc) {
level.Info(r.logger).Log(
"msg", "found existing desktop process dead for console user",
"pid", r.uidProcs[uid].process.Pid,
Expand All @@ -595,18 +595,31 @@ func (r *DesktopUsersProcessesRunner) userHasDesktopProcess(uid string) bool {
return true
}

func processExists(processRecord processRecord) bool {
func (r *DesktopUsersProcessesRunner) processExists(processRecord processRecord) bool {
ctx, cancel := context.WithTimeout(context.Background(), time.Second*2)
defer cancel()

// the call to process.NewProcessWithContext ensures process exists
proc, err := process.NewProcessWithContext(ctx, int32(processRecord.process.Pid))
if err != nil {
level.Info(r.logger).Log(
"msg", "looking up existing desktop process",
"pid", processRecord.process.Pid,
"process_path", processRecord.path,
"err", err,
)
return false
}

path, err := proc.ExeWithContext(ctx)
if err != nil || path != processRecord.path {
level.Info(r.logger).Log(
"msg", "error or path mismatch checking existing desktop process path",
"pid", processRecord.process.Pid,
"process_record_path", processRecord.path,
"err", err,
"found_path", path,
)
return false
}

Expand Down
2 changes: 1 addition & 1 deletion ee/desktop/runner/runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ func TestDesktopUserProcessRunner_Execute(t *testing.T) {
// the cleanup of the t.TempDir() will happen before the binary built for the tests is closed,
// on windows this will cause an error, so just wait for all the processes to finish
for _, p := range r.uidProcs {
if !processExists(p) {
if !r.processExists(p) {
continue
}
// intentionally ignoring the error here
Expand Down