Releases: fherb2/flexible-shared-memory
v0.3.1 - Critical Bug Fix (Lock-Free Correctness)
⚠️ 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:
- Read
seq_end(at end of slot) FIRST - Read all field data
- 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
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.nameproperty after creation
- Names are automatically generated using UUID (format:
inspect()class method: Inspect shared memory structure without attaching- Returns
SHMInspectionInfowith slots, size, and field details
- Returns
expected_typeparameter: Validate dataclass structure when attaching- Automatic DataClass reconstruction: Readers can attach without importing the original DataClass
Breaking Changes
- API Simplification: Writer no longer needs
nameparameter- Before:
SharedMemory(DataClass, name="custom_name") - After:
shm = SharedMemory(DataClass); name = shm.name
- Before:
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 nameFull changelog: https://github.com/fherb2/flexible-shared-memory/blob/main/CHANGELOG.md
v0.2.0 - Self-Describing Header & Performance
[0.2.0] - 2024-12-21
Added
- Self-describing header with automatic configuration detection
- Readers no longer need to specify
slotsparameter (auto-detected from header) - Hash-based header validation prevents dataclass mismatches across processes
overflowflag 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_bytesandarray_flat_sizecaching for performance _read_dict,_write_buffer,_field_status_pool,_value_status_poolnow reusedFieldStatusandValueWithStatusobjects pooled to avoid allocations