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

Race condition between os/exec.Cmd.Wait() and wago.Cmd.Kill() #1

Closed
JonahBraun opened this issue Sep 8, 2015 · 1 comment
Closed

Comments

@JonahBraun
Copy link
Owner

Summary

A known, harmless, race condition exists between these two functions:

  os/exec.(*Cmd).Wait()
  github.com/JonahBraun/wago.(*Cmd).Kill()

Details

We use os/exec.Cmd.Wait to wait for a process to exit and report on that. Before attempting a kill (in response to a FS event), in order to prevent unnecessary log errors, Wago's Cmd.Kill() checks exec.Cmd fields to see if the process is alive. Because Wait() and Kill() must occur in concurrent goroutines, a number of inherent race conditions exist.

These race conditions are harmless. The objective is to ensure a command is killed as quickly as possible in response to an event with the least number of extraneous warnings — and this works most of the time. In the rare worst case scenario, a process exits after the kill conditional

  if cmd == nil || cmd.Process == nil || cmd.ProcessState != nil {

but before the kill itself

  if err := cmd.Process.Kill(); err != nil {

In this case, an extraneous error is printed.

This could probably be resolved by rewriting os/exec to use channels instead fields for conveying process information. However, it should be noted that a race condition will always exist at the OS level. A process could exit in the middle of the Wago code to kill that command.

Please do test Wago with -race, just be aware of this known race condition.

@JonahBraun JonahBraun changed the title os/exec cmd.Wait() race conditions Race condition between os/exec.Cmd.Wait() and wago.Cmd.Kill() Sep 8, 2015
@JonahBraun
Copy link
Owner Author

Runnables are responsible for checking kill chan at appropriate times.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant