Skip to content

Expose opt-in TCP transport termination internally - #3822

Draft
He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/tcp-observed-transport-termination
Draft

He-Pin wants to merge 1 commit into
apache:mainfrom
He-Pin:fix/tcp-observed-transport-termination

Conversation

@He-Pin

@He-Pin He-Pin commented Nov 27, 2026

Copy link
Copy Markdown
Member

Motivation

An outgoing TCP stream can finish before its underlying channel has completed cleanup. An internal consumer coordinating subsequent work needs a separate receipt; actor or graph termination does not establish when the owning selector deregistered the channel.

Modification

  • Add an opt-in, internal stable outgoing flow for an already resolved destination. It shares the existing TCP flow, options, timeouts, and worker; the original outgoing APIs are unchanged.
  • Expose a transport-termination future independently of the connection future. Confirm success only for a proven no-start or after the actual selector has closed and deregistered the channel. Do not report success for an uncertain outcome.
  • Add a deterministic selector-ordering spec without an actor system or sockets.

Result

The ordinary TCP path and Pekko HTTP dependency requirements are unchanged. Consumers may opt into the more precise receipt without adding another TCP wrapper.

Tests

  • JDK 17 + Scala 2.13.18 and 3.3.9: exact changed actor and stream sources compiled; focused SelectorCleanupOrderingSpec passed (1/1 each).
  • Scoped Scalafmt, git diff --check, and existing descriptor comparison for the affected TCP APIs passed.
  • The local proof covers the pure ordering fixture, not socket integration or full sbt/CI.

References

Motivation:
Outbound stream consumers sometimes need to know when the underlying
transport has finished, not just when the stream has stopped. The two
events can occur in a different order.

Modification:
Reuse the existing TCP flow and worker for an already resolved peer,
with a separate opt-in cleanup receipt. Order the receipt on the owning
selector after submitted registration and close work, and do not
confirm cleanup while the channel is open or still registered. Keep
the original outgoing APIs and default behavior.

Result:
Internal consumers can distinguish a never-started dial or confirmed
cleanup from graph completion and uncertain transport termination.
No Pekko HTTP dependency or minimum-version change is included.

Tests:
The exact modified actor and stream sources compiled with JDK 17 on
Scala 2.13.18 and 3.3.9, and SelectorCleanupOrderingSpec passed (1/1)
on each. The fixture models the queue ordering without opening sockets.
Scoped scalafmt, diff checks, and existing JVM descriptor checks passed.
Full sbt and socket integration suites were not run.

References:
Java SelectableChannel.isRegistered; RFC 6455 §4.1 (consumer context).
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