Skip to content

seqlock overflow-consistency fix (#2866) is incomplete: two inline CPU-copy end-write paths still use non-wrapping old_gen + 1 #2890

Description

@phil-opp

⚠️ This issue was created by a scheduled, automated Claude code-review check. It was not filed by a human. Please verify the finding before acting on it. Severity is low (the overflow is practically unreachable); this is a code-consistency / completeness follow-up, not an active runtime risk.

Summary

Issue #2865 (fixed by #2866) asked for the memory-pool seqlock generation counter in apis/python/node/src/lib.rs to use wrapping_add consistently, to match seqlock_end_write's wrapping_add(2) and avoid a debug-build overflow panic. PR #2866 changed only seqlock_begin_write:

// seqlock_begin_write (fixed in #2866)
std::ptr::write_volatile(gen_ptr, pre_write_gen.wrapping_add(1));

However, the else (plain-CPU-copy) branch of write_memory_pool does not call seqlock_end_write; it inlines the end-write increment by hand, and both copies of that inlined code still use non-wrapping + 1. So the exact inconsistency #2865 was about still exists in two places in the same function.

Location

apis/python/node/src/lib.rs — the two inline "end write (infallible CPU copy)" blocks:

Fast path (~line 1800):

// Seqlock: end write (infallible CPU copy, always advances)
unsafe {
    let old_gen = std::ptr::read_volatile(gen_ptr);
    std::ptr::write_volatile(gen_ptr, old_gen + 1);   // <-- non-wrapping
    std::sync::atomic::fence(std::sync::atomic::Ordering::Release);
}

Slow path (~line 1945):

// Seqlock: end write (infallible CPU copy, always advances)
unsafe {
    let old_gen = std::ptr::read_volatile(gen_ptr);
    std::ptr::write_volatile(gen_ptr, old_gen + 1);   // <-- non-wrapping
    std::sync::atomic::fence(std::sync::atomic::Ordering::Release);
}

Why this matters

Suggested fix

Either replace old_gen + 1 with old_gen.wrapping_add(1) in both inline blocks, or (cleaner, avoids future drift) have the CPU-copy path reuse seqlock_end_write(.., copy_ok = true) instead of hand-rolling the end-write increment, so there is a single end-write implementation.

How this was found

A scheduled automated review randomly selected apis/python/node/src/lib.rs, read the seqlock helpers, and cross-checked them against the recently-merged #2866. The function-level helper was fixed, but the two inline duplicates of the same logic were not.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions