host/ports: Add missing mutex lock

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
host: Fix race in image layer handling

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
pkg/iotool: Add io tools package with a thread-safe io.Writer

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
test: Use SafeWriter to avoid races

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
host/ports: Defer mutex unlock for consistency

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
Merge pull request #645 from flynn/fix-races

Fix races
host: Unlock write mutex when attach fails

If this mutex doesn’t get unlocked, the error write will hang trying to
lock at L175.

In practice this was happening when getting the logs for interactive and
non-existent jobs.

Closes #444

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
test: Move Helper cleanup to its own TearDownSuite method

Since the method set of a struct includes methods from anonymous fields,
we can remove any TearDownSuite methods on suites that embed Helper
and only call the Helper cleanup method.

Suites that need to their own TearDownSuite and embed Helper will need
to call cleanup in their implementation.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
pkg/exec: Use host event stream if no attach

If there are no streams to attach to, use the event stream from the host
to get job exit status and error details.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
test: Add HostSuite with tests for failing attaches

TestAttachFinishedInteractiveJob covers #444.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
pkg/exec: Add comments to internal fields of Cmd

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
Merge pull request #650 from flynn/fix-attach-fail

Fix attach failure path
slugbuilder: Bump CURL_TIMEOUT to 10 minutes

CURL_TIMEOUT is the total time spent downloading a file in a buildpack.
The default in the Ruby buildpack is 30s, which will only work reliably
on servers with good connections to S3, this patch bumps it up to 10
minutes.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
slugbuilder, receiver: Implement build caching

Build caching is implemented by downloading a cache tarball from
blobstore before starting the build, and uploading the cache directory
to blobstore after the build is complete.

Closes #619

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
Merge pull request #653 from flynn/build-caching

Implement build caching
slugrunner: exec command

There’s no reason to leave bash lying around in the process tree, so
exec right away instead of forking first.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
 test/runner: Send SIGQUIT to test binary after timeout

This ensures that we get a stack trace from the binary which will help
debug if it has hung somewhere.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
Merge pull request #655 from flynn/slugrunner-exec

slugrunner: exec command
Merge pull request #657 from flynn/test-runner-quit

 test/runner: Send SIGQUIT to test binary after timeout
host/logbuf: Fix race on closed flag

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>