Skip to content

Commit

Permalink
compat attach: fix write on closed channel
Browse files Browse the repository at this point in the history
Waiting on an initialized sync.WaitGroup returns immediately.
Hence, move the goroutine to wait and close *after* reading
the logs.

Fixes: containers#12904
Signed-off-by: Valentin Rothberg <[email protected]>
  • Loading branch information
vrothberg committed Jan 18, 2022
1 parent 0bbf8fa commit 7e30531
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
6 changes: 3 additions & 3 deletions libpod/oci_conmon_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -660,13 +660,13 @@ func (r *ConmonOCIRuntime) HTTPAttach(ctr *Container, req *http.Request, w http.
}
errChan <- err
}()
if err := ctr.ReadLog(context.Background(), logOpts, logChan); err != nil {
return err
}
go func() {
logOpts.WaitGroup.Wait()
close(logChan)
}()
if err := ctr.ReadLog(context.Background(), logOpts, logChan); err != nil {
return err
}
logrus.Debugf("Done reading logs for container %s, %d bytes", ctr.ID(), logSize)
if err := <-errChan; err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion test/apiv2/python/rest_api/test_v2_0_0_container.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def test_resize(self):

def test_attach(self):
self.skipTest("FIXME: Test timeouts")
r = requests.post(self.uri(self.resolve_container("/containers/{}/attach")), timeout=5)
r = requests.post(self.uri(self.resolve_container("/containers/{}/attach?logs=true")), timeout=5)
self.assertIn(r.status_code, (101, 500), r.text)

def test_logs(self):
Expand Down

0 comments on commit 7e30531

Please sign in to comment.