Skip to content

feat: always-on reconnect replay buffer with data integrity verification#63

Merged
Kiryuumaru merged 8 commits into
masterfrom
feat/reconnect-replay-buffer
Apr 27, 2026
Merged

feat: always-on reconnect replay buffer with data integrity verification#63
Kiryuumaru merged 8 commits into
masterfrom
feat/reconnect-replay-buffer

Conversation

@Kiryuumaru
Copy link
Copy Markdown
Owner

Summary

Replaces the opt-in ReconnectBufferSize with an always-on per-channel ring buffer sized from MaxCredits (4MB default). On reconnection, unacknowledged in-flight data is automatically replayed — no data is silently lost.

Changes

Core (src/NetConduit)

  • ChannelSyncState: Ring buffer records all sent data; GetUnacknowledgedDataFrom() replays unacked bytes on reconnect
  • WriteChannel: Constructor creates ChannelSyncState sized to MaxCredits, calls StartRecording() unconditionally
  • StreamMultiplexer: WaitForReconnectPositionsAndReplayAsync + ReplayUnacknowledgedDataToStreamAsync for reconnect protocol
  • FrameReader: Fix ReadSingleFrameAsync PipeReader AdvanceTo deadlock
  • FrameWriter: Reconnect replay support
  • ProcessReconnectAckFrame: Fix off-by-one in offset calculation (16/20 for sessionId/channelCount)

Tests (tests/NetConduit.UnitTests)

  • DisconnectionDataLossTests: 29 tests covering write-after-disconnect, in-flight data replay, byte ordering, concurrent channels, bidirectional integrity
  • PrepareReconnectWait: Registers OnReconnected handlers BEFORE disconnect to fix race condition
  • InFlightLossDuplexPipe + HoldableWriteStream: Test infrastructure to simulate OS send buffer data loss
  • Strengthened 3 tests to verify byte content, not just count

Documentation (docs/)

  • reconnection.md: New "Data Integrity" section explaining ring buffer, replay protocol, and sizing
  • channel-options.md / multiplexer-options.md: MaxCredits dual-role note (credit window + replay buffer)
  • events.md: OnReconnected updated with replay context
  • backpressure.md: MaxCredits reconnection link

Benchmarks

  • Updated for WriteChannel constructor signature change

Testing

  • 29/29 DisconnectionDataLossTests pass
  • All 690 unit tests pass (verified 4 consecutive runs)
  • Benchmarks unaffected

- Updated API index to include new classes: StreamMultiplexer, ReadChannel, WriteChannel, Errors, and StreamPair.
- Expanded concepts index to cover Graceful Shutdown, Heartbeat, and Flush Modes.
- Added detailed documentation for Errors and Exceptions, including MultiplexerException and ChannelClosedException.
- Introduced ReadChannel and WriteChannel documentation, outlining usage, properties, and events.
- Created StreamMultiplexer and StreamPair documentation, detailing lifecycle, channel operations, and advanced methods.
- Added Flush Modes documentation to explain buffering behavior and configuration options.
- Documented Graceful Shutdown protocol and its implementation in multiplexer operations.
- Included Heartbeat mechanism for connection health monitoring and RTT measurement.
- Introduced HoldableWriteStream to simulate OS socket send buffer behavior, allowing writes to be held and dropped to test data loss scenarios.
- Implemented InFlightLossDuplexPipe to utilize HoldableWriteStream for simulating in-flight data loss during disconnects.
- Updated DisconnectionDataLossTests to validate data integrity and reconnection mechanics with in-flight data scenarios.
- Enhanced existing tests to ensure all data is received correctly after disconnects, including baseline, in-flight, and post-reconnect data.
- Added new test for verifying data loss when using HoldableWriteStream during disconnects.
- Replace opt-in ReconnectBufferSize with always-on ring buffer sized from MaxCredits
- ChannelSyncState records all sent data; replays unacknowledged bytes on reconnect
- Fix off-by-one in ProcessReconnectAckFrame offset calculation
- Fix PipeReader AdvanceTo deadlock in ReadSingleFrameAsync
- Fix test reconnect race with PrepareReconnectWait pattern
- Update docs: Data Integrity section, MaxCredits dual-role notes, event descriptions
- Fix incorrect doc claim that credit grants trim the ring buffer
- Strengthen 3 data integrity tests to verify content, not just byte count
- Update benchmarks for WriteChannel constructor signature change
- Add [Trait("Category", "HighMemory")] to DisconnectionDataLossTests
  so it is properly excluded from the main test batch
- Replace hardcoded HighMemory class array with dynamic file scanning
  using Regex to discover classes with [Trait("Category", "HighMemory")]
- Add UseLocalNetConduit=true to TestEntry build step so integration
  tests compile against local source instead of NuGet v2.1.1 which
  lacks the OpenChannelAsync(string) overload
- BuildEntry remains UseLocalNetConduit=false for NuGet packaging
@Kiryuumaru Kiryuumaru force-pushed the feat/reconnect-replay-buffer branch from 52d7e0c to e1c7e85 Compare April 27, 2026 13:10
@Kiryuumaru Kiryuumaru merged commit e4b0748 into master Apr 27, 2026
22 checks passed
@Kiryuumaru Kiryuumaru deleted the feat/reconnect-replay-buffer branch April 27, 2026 14:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant