Skip to content

Ringbuf Reader broken on 32-bit systems due to atomic misalignment #1835

@ebirukov

Description

@ebirukov

When running the built-in tests of ringbuf.Reader on a 32-bit system (e.g., i386), some tests fail due to incorrect behavior of the ring buffer, where unconsumed data appears to remain in the buffer, and expected errors like os.ErrDeadlineExceeded or ErrFlushed are not returned after all samples are read.

This appears to be caused by misaligned access to 64-bit atomic variables (prod_pos, cons_pos) in the ring buffer implementation.

System info:

Architecture: 386 (32-bit x86)

Kernel: Linux 6.1

Go version: 1.24

How to reproduce

Run the ringbuf tests on a 32-bit Linux system

Tests should pass, returning expected ErrFlushed or os.ErrDeadlineExceeded.

=== RUN   TestReaderNoWakeup
    reader_test.go:330: Expected os.ErrDeadlineExceeded from third Read but got <nil>
--- FAIL: TestReaderNoWakeup (0.00s)

=== RUN   TestReaderFlushPendingEvents
    reader_test.go:390: Expected ErrFlushed from third Read but got <nil>
--- FAIL: TestReaderFlushPendingEvents (0.01s)

Version information

github.com/cilium/ebpf v0.19.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions