Skip to content

fix(io): finalize TCP transport cleanup before actor stop#8206

Draft
Aaronontheweb wants to merge 2 commits into
akkadotnet:devfrom
Aaronontheweb:fix/tcp-dispose-async
Draft

fix(io): finalize TCP transport cleanup before actor stop#8206
Aaronontheweb wants to merge 2 commits into
akkadotnet:devfrom
Aaronontheweb:fix/tcp-dispose-async

Conversation

@Aaronontheweb
Copy link
Copy Markdown
Member

Summary

This is a follow-up to @to11mtm's comment on #8132 about async transport disposal in the TCP actor lifecycle:
#8132 (comment)

This change makes the graceful shutdown path explicit instead of relying on PostStop() fallback cleanup.

  • finalize ITransportConnection asynchronously during Tcp.Close
  • finalize ITransportConnection after both FINs during Tcp.ConfirmedClose
  • keep PostStop() abort logic as the fallback for unexpected actor termination
  • make TcpTransportConnection cleanup idempotent across ShutdownAsync, CloseAsync, Abort, and DisposeAsync

Why

TcpTransportConnection already exposed DisposeAsync, but the actor lifecycle never actually used it. In practice that meant:

  • graceful close paths could still fall through to abort-style cleanup in PostStop()
  • ConfirmedClose did not have an explicit async finalization step after the close handshake
  • the transport cleanup contract was harder to reason about across multiple shutdown paths

This PR makes the intended lifecycle explicit and keeps the emergency-stop behavior unchanged.

Testing

  • added focused TcpConnectionBatchingSpec coverage for:
    • graceful close uses async finalization
    • confirmed close uses async finalization after peer FIN
    • unexpected stop still falls back to abort cleanup
  • dotnet test src/core/Akka.Tests/Akka.Tests.csproj -c Release --filter \"FullyQualifiedName~TcpConnectionBatchingSpec|FullyQualifiedName~TcpIntegrationSpec\"
  • dotnet build src/core/Akka/Akka.csproj -c Release
  • dotnet test src/core/Akka.API.Tests/Akka.API.Tests.csproj -c Release

Run async transport finalization during graceful and confirmed closes so TcpConnection no longer falls back to abort cleanup after clean shutdown. Add focused TCP tests covering graceful finalization and unexpected-stop fallback cleanup.
Turn the new shutdown race catches into explicit handled early returns so the transport cleanup path remains idempotent without tripping slopwatch's empty-catch rule.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant