Skip to content

stdbuf: -oL and -o0 have no effect on uniq #16649

Open

Description

@sylvestre

stdbuf -oL / stdbuf -o0 have no effect on uniq: its output is only flushed at exit.

$ (echo first; sleep 1; echo second) | stdbuf -oL uniq | while read l; do echo "$(date +%S) $l"; done

uutils: both lines arrive together after 1s.
GNU 9.12: first arrives immediately, second 1s later.

Same with -o0.

GNU test: bash util/build-gnu.sh && bash util/run-gnu-test.sh tests/misc/stdbuf.sh
It is listed in ignore-intermittent.txt, but it failed in all of the last 40 GnuTests runs.

Part of #14705

Activity

  1. oech3 commented on Nov 17, 2026

    @oech3
    Contributor

    I don't think that this should be good 1st issue sice we need some hack to fix this and not uniq specific things.

  2. VanshajPoonia commented on Nov 18, 2026

    @VanshajPoonia

    I looked into this one. Two things hold the first line back. uniq writes through its own BufWriter, and libstdbuf only changes C stdio, so -oL and -o0 never reach it. And uniq only prints a group's line once the next group starts.

    I agree the first part shouldn't be a uniq-only fix. stdbuf already passes the mode in _STDBUF_O, so a small uucore helper could give utils a stdout writer that flushes per line, or doesn't buffer when it's L or 0. uniq and cut (#11581) could use it first. The second part is uniq-specific and small.

    Would that direction be OK? If so I can open a PR with the helper plus the uniq change.

  3. oech3 commented on Nov 18, 2026

    @oech3
    Contributor

    @anastygnome Is already working on this e.g. #16088

    Personally, I don't wan't to consider LD_PRELOAD things as a bug because this means we restrict API to imprement our tools.
    But _STDBUF_* parser is interesting for static binaries, Window and wasi*.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions