Kernel logging currently calls application handlers while internal locks are held. Slow handlers can delay validation, and handlers that call back into the Kernel can deadlock.
The goal here is to avoid calling application log handlers while Kernel locks are held.
This draft creates a stronger separation between Kernel execution and application behavior by buffering messages per logging connection.
Applications retrieve messages with Drain() and process them independently. Buffers have configurable size limits, discard the oldest messages when full, and report losses. Docker’s non-blocking logging uses a similar buffering approach.
The kernel/native-log-stream branch below explores interruptible reads, allowing applications to consume messages continuously on a reader thread and eliminating the need for the Drain() approach used here:
https://github.com/w0xlt/bitcoin/tree/kernel/native-log-stream
However, this draft starts with explicit draining to keep the initial change smaller and easier to understand while that alternative is discussed and reviewed further.
Feedback on the concept and alternative approaches is welcome.