[Bug]: `container machine logs -f` exits immediately when the log is empty
Los mantenedores suelen responder en 1 día
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 76/100
Línea de trabajo
Empieza en Sources/ContainerCommands/Machine/MachineLogs.swift, alrededor de las líneas 101–119 de tail(), y luego compara el comportamiento con un archivo vacío con la corrección de container logs -f en #2377 y revisa el trabajo del tailer compartido en #2023. Confirma que el seguimiento comienza cuando el log está vacío, mientras que el comportamiento sin seguimiento permanece sin cambios; el issue pide orientación sobre si corregir este archivo o el tailer compartido, así que comprueba qué dirección prefieren los maintainers antes de editar.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I have done the following
- I have searched the existing issues
- If possible, I've reproduced the issue using the 'main' branch of this project
Steps to reproduce
Hey folks, hope you're doing well!
Quick summary: container machine logs -f (without -n) exits right away with no output when the log file is empty, instead of waiting for new lines.
For context, container machine logs shows a machine VM's stdio log, or its boot log with --boot, and -f is meant to keep following it as new lines arrive.
What happens today, traced on main (d5416e63):
- Run
container machine logs -f <machine>(orcontainer machine logs --boot -f <machine>) while that log file is still empty, for example right after the machine starts. - Without
-n,tail()inSources/ContainerCommands/Machine/MachineLogs.swift(around lines 101 to 105) doesguard let data = try fh.readToEnd() else { return }. FileHandle.readToEnd()returnsnilfor a zero byte file (I checked this with a tiny Swift snippet on macOS).- So
tail()returns before it reachesif follow { followFile(fh:) }(around lines 116 to 119). - The command exits immediately with no output and never follows the log.
Minimal repro of the Foundation part:
import Foundation
let path = NSTemporaryDirectory() + "empty.log"
FileManager.default.createFile(atPath: path, contents: Data())
let fh = try FileHandle(forReadingFrom: URL(fileURLWithPath: path))
print(try fh.readToEnd() as Any) // prints nil
Honest note: I haven't run this on a machine VM yet, I traced it in the code and confirmed the readToEnd() behavior with the snippet above.
Problem description
Expected: with -f, an empty log should just start following and print lines as they show up, same as container logs -f does now. Without -f, returning early is totally fine. The -n path (around lines 75 to 98) looks fine too.
This is the sibling of #2374, which was fixed for container logs in #2377. Big thanks to @i098 for that fix! The PR description mentions it deliberately left machine logs alone since they have a separate implementation, so I figured it was worth a dedicated issue.
A small heads up, in case it's useful: #2023 by @gnavadev (nice work on the tailing fixes there) moves both commands into a shared LogTailer.swift. As far as I can tell the shared tailer still has the guard ... else { return } form, so as written it wouldn't cover machine logs and might bring the empty log case back for container logs after it lands. I may well be missing something there, so happy to be corrected.
Which direction would you prefer?
- Mirror #2377 in
MachineLogs.swiftwith} else if let data = try fh.readToEnd() {, so following still starts on an empty file. - Fold the fix into the shared tailer from #2023, so both commands get it in one place.
I'd be glad to send a small PR for whichever you like, and any feedback or tips on how you'd want it tested would be really appreciated. Others are very welcome to weigh in too!
Environment
- OS: macOS 26.6.2 (25G83)
- Xcode: n/a (traced in source, not built locally)
- Container: main at d5416e63
Code of Conduct
- I agree to follow this project's Code of Conduct
- Lenguaje dominante
- Swift
- Estrellas
- 51.1k
- Forks
- 1.8k
- Merge medio
- 2 d 10 h
- PR fusionados (30 d)
- 37
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de apple/container
-
[Bug]: Intermittent failure in PathUtilsTests.testNewDirectoryIsExcludedAndExistingChoiceIsKeptAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
apple/container#2474 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
[Request]: container ls --filter label=key=valuePosiblemente ocupada @kavix la tomó hace 14 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
apple/container#2403 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Request]: Improve robustness and path resolution in ensure-hawkeye.shPosiblemente ocupada @denizguney la tomó hace 38 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
[Bug]: kernel download hangs forever when the server stops sendingPosiblemente ocupada @devops-thiago la tomó hace 40 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
apple/container#2327 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
[Bug]: container export -o deletes an existing directoryPosiblemente ocupada @devops-thiago la tomó hace 40 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
apple/container#2325 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de apple/container
Issues similares
-
a: plugins d: docs/ fyi-macos P2 platform-ios platform-macos team-ios
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 67/100
swiftlang/github-workflows#352 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
jphacks/kz_2601#1375 · 1 comentario ·
Los mantenedores suelen responder en 1 día