concourse: Missing build logs - containerd

Summary

When using the containerd runtime, we are seeing an issue when Concourse is managed. The problem is that after the worker gets reselected (web restart - drain etc.) the worker starts reporting/emitting build logs rather randomly and some logs are lost. This impacts logs of jobs that are running, in parallel with the concourse update. I think this could potentially block users from actually wanting to migrate to containerd, if we are not able to find a solution.

Steps to reproduce

Run concourse deploy and have other long running jobs that emit build logs at the moment

Expected results

All build logs are emitted correctly and visualised in the UI as before the update

Actual results

Image

Check the welcome message, before the recreate and after the recreate. Notice how after we have some logs that are not present in the UI, although the container still resumes it’s execution just fine.

Additional context

I have tested this in a bosh environment, haven’t been able to test it in docker/kubernetes

Triaging info

  • Concourse version: v7.13.1, v7.11.2, v7.11.0
  • Browser (if applicable): Chrome
  • Did this used to work? Worked/works fine with guardian

About this issue

  • Original URL
  • State: open
  • Created 2 years ago
  • Comments: 18 (18 by maintainers)

Commits related to this issue

Most upvoted comments

That’s great to hear - thanks so much for jumping on this and getting it resolved.

Without prior context on this part of the functionality, it was definitely a bit tough for me to wrap my head around the entire implementation. We actually ran into the same issues with closing and opening attaches just yesterday, so your insights and the way you walked through your approach have been incredibly helpful in understanding the whole picture.

Looking forward to the PR. We’ll validate it on our side as well. Thanks for pulling this together so quickly!

Thank you guys so much for figuring out why this is happening. It really helped with trying to figure out a solution, which I think I found!

Image

No more dropped logs!!

My fix here is basically what Ivan was going for, managing the cio.IO streams. Order of operation really matters here. We do have to attach first before closing the old streams. Closing the old streams first results in the FIFO’s being deleted and the resulting re-attach failing.

I’m pushing my WIP fix to a branch here: https://github.com/concourse/concourse/compare/master...issue-9189

I’ll clean it up more tomorrow and get it PR’d for the next release.

I spent some time digging into intermittent missing task logs after ATC restart and I found:

  • There were multiple file descriptors open on the same task-stdout FIFO, confirmed with lsof /run/containerd/fifo/.../task-stdout after restarting the ATC. This happens because the ATC triggers a fresh call to Attach after reconnecting to the worker.
  • Each Attach call (via LoadProcess + cio.NewAttach) seems to create a new reader on the FIFO. Since FIFOs deliver data to the first reader that reads it, I suspect this is causing log lines to be split or lost across multiple readers.

My suspicion:

The Concourse worker is unintentionally creating redundant attaches without properly closing old ones, leading to multiple competing readers on task-stdout.

What I tried

As a stopgap, I added code to force-close any existing FDs tied to task-stdout before performing a new attach(here):

pidNum := os.Getpid()
fdDir := fmt.Sprintf("/proc/%d/fd", pidNum)
files, _ := os.ReadDir(fdDir)

for _, file := range files {
	fdPath := filepath.Join(fdDir, file.Name())
	link, err := os.Readlink(fdPath)
	if err != nil {
		continue
	}
	if strings.Contains(link, "task-stdout") {
		fdNum := 0
		fmt.Sscanf(file.Name(), "%d", &fdNum)
		fmt.Printf("Closing FD %d -> %s\n", fdNum, link)
		syscall.Close(fdNum)
	}
}

This brute-force cleanup resolved the issue right away, but it’s clearly not an ideal or long-term solution.

I’m continuing to explore a more robust approach by explicitly managing cio.IO streams, so we can cleanly Cancel() and Close() old attaches without resorting to closing FDs manually.

If anyone has ideas or prior experience with managing cio.IO more predictably, it would be highly appreciated!

Tested with:

jobs:
- name: hello-counter-job
  plan:
  - config:
      image_resource:
        name: ""
        source:
          repository: cgr.dev/chainguard/bash
          tag: latest
        type: registry-image
      platform: linux
      run:
        args:
        - -ec
        - |-
          for i in {1..600};  do
            echo "Hello $i"
            sleep 1
          done  | tee /tmp/mylog.txt
        path: /bin/bash
    privileged: true
    task: hello-counter-task

And the file in the container is correctly filled, however after the restart of the webs, there are no longer any build logs in the UI of Concourse, which imho confirms the worker resumes the build execution but fails to re-establish the log stream.

So:

  • The build continues to run and completes successfully - ✅
  • Logs are still written inside the container (e.g., /tmp/mylog.txt) - ✅
  • But the log stream from the worker to the web is broken, so:
    • Nothing is sent to the Concourse web node - ❌
    • Nothing is written to the DB - ❌
    • The UI shows no logs after that point - ❌

The issues occurs with all of the versions when using containerd, also both issues start to occur when Concourse is being deployed. We do rolling update with two web nodes and multiple worker nodes. We always have a running web, there is no downtime of the UI, or anything else. Because of the web restarts we are seeing multiple “selected worker” statements. Our workers start to recreate only after all webs have finished, but even then the worker which is still not recreated stops emitting build logs for some reason. And it is not that all of them are not emitting. Some are dropped, while others continue as seen in the screenshot. Sometimes for durations of minutes we see build logs loss. To answer the second question, Yes, with guardian this is not reproducible, with containerd it reproduces each time.

For the UID duplication: v7.13.1, 2 web nodes, steps: bosh deploy —recreate flag. Haven’t been able to check the logs, but when I reproduce it, I will make sure to do so.