Skip to content

Commit

Permalink
Merge pull request #3204 from apostasie/dev-3187
Browse files Browse the repository at this point in the history
Workaround delayed log file creation
  • Loading branch information
AkihiroSuda authored Jul 9, 2024
2 parents cc3c14c + c628ef1 commit 61ac21d
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion pkg/logging/json_logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"strings"
"time"

"github.com/containerd/containerd/errdefs"
"github.com/containerd/containerd/runtime/v2/logging"
"github.com/containerd/log"
"github.com/containerd/nerdctl/v2/pkg/logging/jsonfile"
Expand Down Expand Up @@ -129,7 +130,16 @@ func (jsonLogger *JSONLogger) PostProcess() error {
func viewLogsJSONFile(lvopts LogViewOptions, stdout, stderr io.Writer, stopChannel chan os.Signal) error {
logFilePath := jsonfile.Path(lvopts.DatastoreRootPath, lvopts.Namespace, lvopts.ContainerID)
if _, err := os.Stat(logFilePath); err != nil {
return fmt.Errorf("failed to stat JSON log file ")
// FIXME: this is a workaround for the actual issue, not a real solution
// https://github.com/containerd/nerdctl/issues/3187
if errors.Is(err, errdefs.ErrNotFound) {
log.L.Warnf("Racing log file creation. Pausing briefly.")
time.Sleep(200 * time.Millisecond)
_, err = os.Stat(logFilePath)
}
if err != nil {
return fmt.Errorf("failed to stat JSON log file %w", err)
}
}

if checkExecutableAvailableInPath("tail") {
Expand Down

0 comments on commit 61ac21d

Please sign in to comment.