Skip to content

Commit abe86f2

Browse files
committed
Merge pull request flynn#952 from flynn/attach-client-exit-code
pkg/cluster,controller,dashboard: Return -1 from attach client if exit code unknown
2 parents fbea912 + 00ca50f commit abe86f2

File tree

3 files changed

+18
-15
lines changed

3 files changed

+18
-15
lines changed

controller/jobs.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,8 +279,11 @@ func (c *controllerAPI) JobLog(ctx context.Context, w http.ResponseWriter, req *
279279
return
280280
}
281281
if tail {
282-
ch <- &sseLogChunk{Event: "exit", Data: []byte(fmt.Sprintf(`{"status": %d}`, exit))}
283-
return
282+
// Send eof if we don't know the exit code
283+
if exit != -1 {
284+
ch <- &sseLogChunk{Event: "exit", Data: []byte(fmt.Sprintf(`{"status": %d}`, exit))}
285+
return
286+
}
284287
}
285288
ch <- &sseLogChunk{Event: "eof"}
286289
} else {

dashboard/app/lib/javascripts/dashboard/stores/app-jobs.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ var AppJobs = Dashboard.Stores.AppJobs = Dashboard.Store.createClass({
3535
if (event.name === "JOB_EXIT") {
3636
var hasChanges = false;
3737
this.state.processes.forEach(function (process) {
38-
if (process.id === event.jobId) {
38+
if (process.id === event.jobId && event.status !== undefined) {
3939
hasChanges = true;
4040
process.state = event.status === 0 ? "down" : "crashed";
4141
}

pkg/cluster/attach.go

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func (c *attachClient) Wait() error {
136136
func (c *attachClient) Receive(stdout, stderr io.Writer) (int, error) {
137137
if c.wait != nil {
138138
if err := c.wait(); err != nil {
139-
return 0, err
139+
return -1, err
140140
}
141141
c.mtx.Unlock()
142142
}
@@ -148,55 +148,55 @@ func (c *attachClient) Receive(stdout, stderr io.Writer) (int, error) {
148148
if err == io.EOF && stdout == nil && stderr == nil {
149149
err = nil
150150
}
151-
return 0, err
151+
return -1, err
152152
}
153153
switch frameType {
154154
case host.AttachData:
155155
stream, err := r.ReadByte()
156156
if err != nil {
157-
return 0, err
157+
return -1, err
158158
}
159159
var out *io.Writer
160160
switch stream {
161161
case 1:
162162
if stdout == nil {
163-
return 0, errors.New("attach: got frame for stdout, but no writer available")
163+
return -1, errors.New("attach: got frame for stdout, but no writer available")
164164
}
165165
out = &stdout
166166
case 2:
167167
if stderr == nil {
168-
return 0, errors.New("attach: got frame for stderr, but no writer available")
168+
return -1, errors.New("attach: got frame for stderr, but no writer available")
169169
}
170170
out = &stderr
171171
default:
172-
return 0, fmt.Errorf("attach: unknown stream %d", stream)
172+
return -1, fmt.Errorf("attach: unknown stream %d", stream)
173173
}
174174
if _, err := io.ReadFull(r, buf[:]); err != nil {
175-
return 0, err
175+
return -1, err
176176
}
177177
length := int64(binary.BigEndian.Uint32(buf[:]))
178178
if length == 0 {
179179
*out = nil
180180
continue
181181
}
182182
if _, err := io.CopyN(*out, r, length); err != nil {
183-
return 0, err
183+
return -1, err
184184
}
185185
case host.AttachExit:
186186
if _, err := io.ReadFull(r, buf[:]); err != nil {
187-
return 0, err
187+
return -1, err
188188
}
189189
return int(binary.BigEndian.Uint32(buf[:])), nil
190190
case host.AttachError:
191191
if _, err := io.ReadFull(r, buf[:]); err != nil {
192-
return 0, err
192+
return -1, err
193193
}
194194
length := int64(binary.BigEndian.Uint32(buf[:]))
195195
errBytes := make([]byte, length)
196196
if _, err := io.ReadFull(r, errBytes); err != nil {
197-
return 0, err
197+
return -1, err
198198
}
199-
return 0, errors.New(string(errBytes))
199+
return -1, errors.New(string(errBytes))
200200
}
201201
}
202202
}

0 commit comments

Comments
 (0)