Skip to content

fix(logger): avoid u8 counter overflow in buffered logger (#728) - #799

Merged
ytakano merged 2 commits into
tier4:mainfrom
ytakano:fix/buffered-logger-counter-overflow-728
Nov 17, 2026
Merged

ytakano merged 2 commits into
tier4:mainfrom
ytakano:fix/buffered-logger-counter-overflow-728

Conversation

@ytakano

@ytakano ytakano commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Description

The buffered logger counted printed messages in a u8 with n += 1, which panics on the 256th message in debug builds. The logger task then moved to the panicked scheduler and all console output stopped.

  • Use wrapping_add for the yield counter.
  • If the buffered logger task stops, e.g., because it panicked, print the messages still queued, including the panic report, and print later messages directly to the console.

Related links

Closes #728

How was this PR tested?

  • scripts/ci.sh passes on my machine.

Notes for reviewers

The buffered logger counted printed messages in a `u8` with `n += 1`,
which panics on the 256th message in debug builds. The logger task then
moved to the panicked scheduler and all console output stopped.

- Use `wrapping_add` for the yield counter.
- If the buffered logger task panics, fall back to the raw console via
  the new `awkernel_lib::logger::unset_buf_console()` so later output,
  including the panic report, stays visible.

Closes tier4#728

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ytakano
ytakano marked this pull request as ready for review November 16, 2026 08:26
@ytakano
ytakano requested a review from atsushi421 November 16, 2026 08:27
Comment thread awkernel_lib/src/logger.rs Resolved
The panic handler queues the panic report into the buffered logger's
channel before unwinding, and the receiver was dropped before the
fallback guard ran, so the report and all queued messages were lost.

- Move the guard into the logger body, after the receiver, and drain
  the queue to the console when it is dropped.
- Switch to direct output by clearing BUFFERED_LOGGER under its lock
  instead of rewriting the unsynchronized `buf_console` pointer, and
  remove `awkernel_lib::logger::unset_buf_console()`.
- Print the fallback notice as a static string, without allocating
  during unwinding.

Co-Authored-By: Claude Fable 5.2 <[email protected]>
@ytakano
ytakano merged commit fd13859 into tier4:main Nov 17, 2026
1 check 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.

buffered_logger: u8 counter overflow stops all log output after 256 messages in debug builds

2 participants