veyron/lib/exec: remove data race between Wait and Clean.

The race manifests itself when a goroutine is blocked on handle.Wait (or
handle.Wait has timed out, but the background goroutine started by handle.Wait
is still blocked on cmd.Wait), and another goroutine calls Clean.  Furthermore,
calling cmd.Wait more than once on the same cmd returns an error even if done
serially, so it's a good idea to avoid that.

The fix is to synchronize the calls to cmd.Wait to ensure that Wait gets called
only once, and in a thread-safe manner.  Added a test case that used to trigger
the race with --race.

Change-Id: I903fea8ebbcf5e87142100b6aead55bf913ca468
2 files changed
tree: 3fa22ebf87b8010e06c4d26e6af3518a5ea8970e
  1. lib/
  2. profiles/
  3. runtimes/
  4. security/
  5. services/
  6. tools/