Skip to content

refactor: complexity cleanup across protocol state machines, body pumps, and stages (+3 bug fixes)#66

Merged
st0o0 merged 21 commits into
mainfrom
refactor/complexity-cleanup
Jul 5, 2026
Merged

refactor: complexity cleanup across protocol state machines, body pumps, and stages (+3 bug fixes)#66
st0o0 merged 21 commits into
mainfrom
refactor/complexity-cleanup

Conversation

@st0o0

@st0o0 st0o0 commented Jul 5, 2026

Copy link
Copy Markdown
Member

Summary

Audit-driven complexity cleanup across the protocol layer (H1.0/H1.1/H2/H3), body pumps, and
connection stages. Net effect: dead code removed, duplicated lifecycle/teardown logic collapsed
into single entry points, and implicit boolean-flag state replaced with explicit state enums.
Includes three bug fixes found during the audit. No public API or wire-format changes.

Bug fixes

  • lifecycle: stop surviving listeners when a sibling listener dies during startup (ServerSupervisorActor)
  • body: refund the reserved connection window when a body read fails (FlowControlledBodyPump)
  • pooling: allow Return before the first Rent registers a pool factory (ConnectionObjectPool)

Refactorings

New shared components (extracted from duplicated per-protocol code)

  • ConnectionRateGuard / ReconnectPolicy — shared rate-guard and reconnect logic, previously duplicated across H1.0/H1.1 client and server state machines
  • Http3OutboundWriter — single owner of H3 framing and pump credit, extracted from client/server session managers
  • PumpSlotLifecycle — deduplicated slot lifecycle shared by Serial/Multiplexed/FlowControlled body pumps, with unified cancel discipline

State made explicit

  • H1.1 client connection lifecycle modeled as an explicit state enum (was scattered boolean flags)
  • H2 stream lifecycle as explicit state with a single ReleaseStream teardown path

Decomposition of oversized methods

  • H2/H3 EncodeRequest: connection bootstrap and body-send strategy ladder extracted
  • H1.1 DecodeClientData / OnResponse: streaming-resume, request-dispatch, and drain-scheduling helpers extracted; response-completion epilogue and keep-alive rearm unified
  • H3 StreamManager: body-dispatch and FIN epilogues extracted; headers-frame triage and decode error handling consolidated
  • ApplicationBridgeStage / connection stage logics: per-request bookkeeping consolidated into RequestSlot with a single FinishRequest; drain predicates deduped, completion entry points unified

Dead code removal

  • Write-only/dead StreamState members in H2/H3, pass-through TryDecodeEof, dead _streamRunning flag, obsolete BodyReadContinue starvation guard (superseded by force-async reads)

Tests

New specs for the extracted components (ConnectionRateGuardSpec, ReconnectPolicySpec,
Http3OutboundWriterSpec, Http2StreamStateLifecycleSpec, ServerSupervisorActorSpec) plus
coverage for the three bug fixes. Full unit + stage suite passes.

st0o0 added 21 commits July 5, 2026 09:37
@st0o0
st0o0 merged commit f32fbef into main Jul 5, 2026
5 checks passed
@st0o0
st0o0 deleted the refactor/complexity-cleanup branch July 5, 2026 08:05
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