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
host/logbuf: Fix race on closed flag

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
host/logbuf: Don’t leak log tailers

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
Godeps: Use our fork of ActiveState/tail

This is a temporary measure until
ActiveState/tail#42 with StopAtEOF is merged.

Signed-off-by: Jonathan Rudenberg <jonathan@titanous.com>
host/logbuf: Fix race during close

When the log file is closed, any readers should read until the EOF so
that they don’t miss lines.

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