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

Use signal pipe to make live reload better. #1843

Merged
merged 1 commit into from
Apr 4, 2018
Merged

Conversation

klizhentas
Copy link
Contributor

@klizhentas klizhentas commented Apr 3, 2018

This commit allows teleport parent process to track
the status of the forked child process using os.Pipe.

Child process signals success to parent process by writing
to Pipe.

This allows HUP and USR2 to be more intelligent as they
can now detect the failure or success of the process.

fixes #1844

@klizhentas
Copy link
Contributor Author

retest this please

return
}
log.Infof("Received message from pid %v: %v", p.Pid, string(data[:len]))
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel() is called twice.

log.Debugf("Failed to write to pipe: %v", trace.DebugReport(err))
return
}
cancel()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cancel() called twice.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's on purpose to ensure all code paths are covered, cancel function is re-entrable

case <-time.After(signalPipeTimeout):
return trace.BadParameter("Failed to write to parent process pipe")
case <-messageSent.Done():
log.Infof("Signalled success to parent process")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Signaled. Might want to use structured logging like below as well.

if !trace.IsNotFound(err) {
return trace.Wrap(err)
}
log.Debugf("No signal pipe found, not going to signal")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe change message to, "No signal pipe to import, must be first Teleport process."

}
defer signalPipe.Close()

messageSent, cancel := context.WithCancel(context.TODO())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since in this case context.TODO() will never be replaced (it's only used to signal when the write is complete), I'd use context.Background(). That way it won't highlight TODO in editors.

@@ -441,6 +431,20 @@ func NewTeleport(cfg *Config) (*TeleportProcess, error) {
return nil, trace.BadParameter("all services failed to start")
}

if err := process.writeToSignalPipe(fmt.Sprintf("Process %v has started.", os.Getpid())); err != nil {
log.Warningf("Failed to write to signal pipe: %v", trace.DebugReport(err))
Copy link
Contributor

@russjones russjones Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like an error should be returned here? Is it okay to fail writing to the pipe?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it's ok, as it's not critical for process, it could mean that parent process has crashed. I will add comment.

This commit allows teleport parent process to track
the status of the forked child process using os.Pipe.

Child process signals success to parent process by writing
to Pipe.

This allows HUP and USR2 to be more intelligent as they
can now detect the failure or success of the process.
@klizhentas
Copy link
Contributor Author

retest this please

@klizhentas klizhentas merged commit 4849a71 into master Apr 4, 2018
@klizhentas klizhentas deleted the sasha/hupz branch April 4, 2018 01:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Teleport HUP is unreliable with systemd
3 participants