mirror of
https://github.com/tailscale/tailscale.git
synced 2026-09-14 23:11:39 -04:00
This adds the following helpers:
* WaitLength waits until the buffer is non-empty or a context is canceled.
It supports batchDelays so that even if data is ready, it blocks
until the delay is over. This is useful for how we upload logs for iOS,
where we deliberately wait a few minutes to reduce wakeup costs.
* DiscardOversize asynchronously discards data in the buffer
once it exceeds the specified maxSize. It takes in an optional frameLen
to ensure discarding maintains consistent frames in the buffer.
This avoids known problems with today's ring buffer where we can get
torn frames that lead to silent data corruption.
An alternative approach would be to synchronously delete data upon
an oversize condition at Write time, but there are two reasons
not to do that:
1. Doing requires teaching each Buffer implementation about
the concept of framing, which the interface deliberately avoids.
2. We want the write path to be extremely fast as we never want to
be blocking production logic. Going over maxSize momentarily is
considered a better tradeoff than synchronously blocking writes.
* StreamReader converts a non-blocking Buffer reader into a blocking one.
This exists primarily for debugging where you can simply stream
the entirety of a buffer to stdout.
We also adjust the package to avoid wrapping io.EOF and ErrEmpty
as those are sentinel errors with very specific meanings.
Updates tailscale/corp#21363
Signed-off-by: Joe Tsai <joetsai@digital-static.net>