Skip to content

Releases: fherb2/flexible-shared-memory

v0.3.1 - Critical Bug Fix (Lock-Free Correctness)

22 Dec 20:28

Choose a tag to compare

⚠️ CRITICAL BUG FIX - Update Immediately!

This release fixes a critical race condition in the lock-free sequence number checking mechanism.

What was fixed?

The reader now correctly reads sequence numbers in reverse order:

  1. Read seq_end (at end of slot) FIRST
  2. Read all field data
  3. Read seq_begin (at start of slot) LAST

The previous implementation (0.3.0) read seq_begin first, which could result in reading inconsistent data during concurrent writes.

Impact

  • High-frequency write scenarios were most affected
  • Could result in reading mixed old/new data
  • No data corruption in memory, but readers could see inconsistent snapshots

Who should update?

All users running version 0.3.0 should update immediately, especially if:

  • Using high-frequency writes (>100 Hz)
  • Multiple readers accessing the same data
  • Data consistency is critical for your application

Technical Details

The two-marker approach (seq_begin, seq_end) is fundamentally correct, but requires reading in the proper order to guarantee lock-free consistency. See CHANGELOG.md for full technical explanation.

Full changelog: https://github.com/fherb2/flexible-shared-memory/blob/main/CHANGELOG.md

v0.3.0 - Auto-Generated Names & Inspection

22 Dec 13:56

Choose a tag to compare

New Features

  • Auto-generated shared memory names: Writers no longer require manual name specification
    • Names are automatically generated using UUID (format: shm_<8-char-hex>)
    • Names are accessible via shm.name property after creation
  • inspect() class method: Inspect shared memory structure without attaching
    • Returns SHMInspectionInfo with slots, size, and field details
  • expected_type parameter: Validate dataclass structure when attaching
  • Automatic DataClass reconstruction: Readers can attach without importing the original DataClass

Breaking Changes

  • API Simplification: Writer no longer needs name parameter
    • Before: SharedMemory(DataClass, name="custom_name")
    • After: shm = SharedMemory(DataClass); name = shm.name

Changed

  • Improved error messages for structure mismatches
  • Python version requirement: Now requires Python 3.7+ (stable field ordering)

Migration Guide

Before (0.2.0):

shm = SharedMemory(SensorData, name="sensor_buffer", slots=5)
pipe.send("sensor_buffer")

After (0.3.0):

shm = SharedMemory(SensorData, slots=5)
pipe.send(shm.name)  # Auto-generated name

Full changelog: https://github.com/fherb2/flexible-shared-memory/blob/main/CHANGELOG.md

v0.2.0 - Self-Describing Header & Performance

21 Dec 16:58

Choose a tag to compare

[0.2.0] - 2024-12-21

Added

  • Self-describing header with automatic configuration detection
  • Readers no longer need to specify slots parameter (auto-detected from header)
  • Hash-based header validation prevents dataclass mismatches across processes
  • overflow flag for FIFO mode - indicates when older data was lost due to buffer overflow
  • Comprehensive test suite with fork/spawn coverage (~96% code coverage, 200+ tests)

Changed

  • Performance: Object pooling reduces allocations by ~83% (6x improvement in read-heavy workloads)
  • Performance: Pre-cached field metadata eliminates repeated calculations
  • String truncation now happens on character boundary before UTF-8 encoding (more predictable)
  • Improved error messages for dataclass structure mismatches

Fixed

  • UTF-8 string truncation now correctly truncates by character count, not byte count
  • Security: Removed eval() usage in field deserialization (CVE prevention)
  • Field status tracking now correctly uses object pooling for lock-free performance
  • Header hash validation now correctly compares reader's layout with stored layout

Internal

  • Added string_max_bytes and array_flat_size caching for performance
  • _read_dict, _write_buffer, _field_status_pool, _value_status_pool now reused
  • FieldStatus and ValueWithStatus objects pooled to avoid allocations