[Bug]: `container logs -n N` truncates the oldest line when it exceeds the 1024-byte read chunk
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 76/100
Research direction
Start at Application.ContainerLogs.tail(fh:n:follow:) and reproduce the issue with the supplied container logs -n 1 logbug | wc -c command. Trace the backwards 1024-byte reads and verify that container logs -n N preserves the complete oldest returned line, including when it crosses a chunk boundary.
Written by the indexing model from the issue text.
Description
Steps to reproduce
- Start a container that logs a single line longer than 1024 bytes:
container run -d --name logbug alpine \ sh -c 'printf "START"; i=0; while [ $i -lt 3000 ]; do printf "X"; i=$((i+1)); done; printf "END\n"; sleep 120' container logs -n 1 logbug | wc -c
Current behavior
Returns 1024 bytes, and the output starts in the middle of the line — the leading START is gone. The oldest (here, only) returned line is truncated.
Expected behavior
Returns the full line (~3009 bytes), matching container logs logbug (without -n), which returns the complete line.
More generally, container logs -n N truncates the oldest of the N returned lines whenever the last N lines span more than one 1024-byte read chunk (e.g. three ~800-byte lines with -n 2).
Root cause
Application.ContainerLogs.tail(fh:n:follow:) reads the file backwards in 1024-byte chunks and stops as soon as lines.count >= n. When the last N lines span more than one chunk, the first line in the buffer is a fragment truncated at the chunk boundary (the buffer starts mid-line while offset > 0), and Array(lines.suffix(n)) keeps it. It should keep reading until it has more than N non-empty lines (so the partial leading line is dropped) or reaches the start of the file.
Environment
- container 1.1.0
- macOS 26.5 (Tahoe), Apple Silicon (M-series)
- Dominant language
- Swift
- Stars
- 50.1k
- Forks
- 1.8k
- Avg merge
- 2d 2h
- Merged PRs (30d)
- 19
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from apple/container
-
Difficulty 1/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
type: docs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
googleapis/google-cloud-swift#971 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
bitcoindevkit/bdk-ffi#1125 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
mozilla-mobile/firefox-ios#35743 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 84/100
manaflow-ai/cmux#13417 ·