Skip to content

fix(logging): keep short-write progress for protobuf TCP access logs - #1835

Merged
FlorentinDUBOIS merged 3 commits into
mainfrom
fix/protobuf-tcp-access-log-write-all
Oct 3, 2026
Merged

FlorentinDUBOIS merged 3 commits into
mainfrom
fix/protobuf-tcp-access-log-write-all

Conversation

@FlorentinDUBOIS

@FlorentinDUBOIS FlorentinDUBOIS commented Oct 3, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1830

Cause

CAUSE: command/src/logging/logs.rs protobuf arm of InnerLogger::log_access (LoggerBackend::Tcp(socket) => socket.write(bytes) at bd19a78e) -> the count of a single TcpStream::write is discarded by .map(|_| ()), so a prefix-only write is reported as success and nothing retries the remainder -> SYMPTOM: the tcp:// access-log stream carries a truncated record, and the decoder reads the next record's length-delimited bytes as the first one's remainder (decode_length_delimited -> BufferUnderflow).

Change

  • The protobuf Tcp arm now sends the record through write_stream_record, which uses write_all, as the ASCII Tcp arm in log_arguments already did. An I/O error still returns to log_access, which reports it and revives the backend.
  • The framing (length delimiter, record, two zero bytes) moves unchanged into encode_protobuf_access_log, so a test can drive framing and writing through a substitutable sink. LoggerBackend::Tcp holds a concrete TcpStream, so the stream write is a small generic helper.
  • Docs: doc/observability.md describes the protobuf framing and why tcp:// uses write_all; CHANGELOG entry under Unreleased / Fixed.

Regression test

short_writes_keep_consecutive_protobuf_records_framed frames two distinct ProtobufAccessLog records, writes them through a ShortWriteSink that accepts at most 7 bytes per call, then decodes both in order and checks each one's two zero bytes and that nothing trails.

  • Red: write_stream_record set to the pre-fix arm semantics (stream.write(bytes).map(|_| ())). The helper does not exist on origin/main, so this follows the module's documented "restore the pre-fix arm" convention instead of a literal origin/main run:
    every record decodes from the stream, in order: DecodeError { description: BufferUnderflow, stack: [] } -> test result: FAILED. 5 passed; 1 failed
  • Green with write_all: test result: ok. 6 passed; 0 failed

a_stream_record_error_is_propagated checks that a sink error keeps its kind (BrokenPipe).

Validation (on 1e7abca)

  • cargo +nightly fmt --check -> exit 0
  • cargo +1.93.1 clippy --all-features --all-targets --locked -- -D warnings -> exit 0
  • RUSTDOCFLAGS="-D warnings" cargo +1.93.1 doc --no-deps --locked -p sozu-lib -p sozu-command-lib -p sozu -> exit 0
  • cargo +1.93.1 test -p sozu-command-lib --locked --all-features -> test result: ok. 237 passed; 0 failed (lib) plus doc/integration targets ok
  • python3 .github/scripts/check_doc_citations.py --root . --base origin/main -> exit 0

Not changed here

The protobuf File arm has the same single-write shape: MultiLineWriter::write hands a record at least as large as its buffer straight to File::write. The issue covers the TCP arm only, so File (and Stdout, whose result is ignored) are left for a follow-up.

The protobuf `Tcp` arm of `InnerLogger::log_access` called
`TcpStream::write` once and mapped any byte count to success. A stream
may accept only a prefix, so a short write truncated the record and the
decoder read the next record's bytes as its remainder.

Send the record through `write_stream_record`, which uses `write_all`
like the ASCII `Tcp` arm. Move the unchanged framing into
`encode_protobuf_access_log` so a test can drive framing and writing
through a short-writing sink and decode consecutive records.

Fixes #1830

Signed-off-by: Florentin Dubois <[email protected]>
@FlorentinDUBOIS
FlorentinDUBOIS merged commit 1a1677b into main Oct 3, 2026
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Protobuf TCP access logs discard short-write progress

1 participant