Skip to content

Commit

Permalink
control-c works
Browse files Browse the repository at this point in the history
  • Loading branch information
dadgar committed Jul 25, 2016
1 parent cbcb320 commit 67fe934
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
16 changes: 15 additions & 1 deletion api/fs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"net/http"
"net/url"
"strconv"
"sync"
"time"
)

Expand Down Expand Up @@ -362,7 +363,9 @@ func (a *AllocFS) Logs(alloc *Allocation, follow bool, task, logType, origin str
type FrameReader struct {
frames <-chan *StreamFrame
cancelCh chan struct{}
closed bool

closedLock sync.Mutex
closed bool

unblockTime time.Duration

Expand Down Expand Up @@ -395,6 +398,13 @@ func (f *FrameReader) Offset() int {
// Read reads the data of the incoming frames into the bytes buffer. Returns EOF
// when there are no more frames.
func (f *FrameReader) Read(p []byte) (n int, err error) {
f.closedLock.Lock()
closed := f.closed
f.closedLock.Unlock()
if closed {
return 0, io.EOF
}

if f.frame == nil {
var unblock <-chan time.Time
if f.unblockTime.Nanoseconds() > 0 {
Expand All @@ -412,6 +422,8 @@ func (f *FrameReader) Read(p []byte) (n int, err error) {
f.byteOffset = int(f.frame.Offset)
case <-unblock:
return 0, nil
case <-f.cancelCh:
return 0, io.EOF
}
}

Expand All @@ -430,6 +442,8 @@ func (f *FrameReader) Read(p []byte) (n int, err error) {

// Close cancels the stream of frames
func (f *FrameReader) Close() error {
f.closedLock.Lock()
defer f.closedLock.Unlock()
if f.closed {
return nil
}
Expand Down
2 changes: 1 addition & 1 deletion command/agent/fs_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ func (s *HTTPServer) Stream(resp http.ResponseWriter, req *http.Request) (interf
framer.Run()
defer framer.Destroy()

err := s.stream(offset, path, fs, framer, nil)
err = s.stream(offset, path, fs, framer, nil)
if err != nil && err != syscall.EPIPE {
return nil, err
}
Expand Down

0 comments on commit 67fe934

Please sign in to comment.