Skip to content

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

Closed
Aaronontheweb wants to merge 3 commits into
akkadotnet:devfrom
Aaronontheweb:fix/tcp-dispose-async
Closed

Aaronontheweb wants to merge 3 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.
Aaronontheweb and others added 2 commits May 11, 2026 15:29
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.
@Aaronontheweb Aaronontheweb added this to the 1.5.70 milestone Jun 15, 2026
@Aaronontheweb Aaronontheweb modified the milestones: 1.5.70, 1.5.71 Jul 3, 2026
@Aaronontheweb Aaronontheweb modified the milestones: 1.5.71, 1.5.72 Aug 27, 2026
@Aaronontheweb

Copy link
Copy Markdown
Member Author

Closing: the same problem was fixed differently in #8630/#8636 (TcpConnection's graceful close path).

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