Skip to content

No way to reclaim a socket's descriptor: blocks mid-stream TLS upgrade and socket._handle.fd #35

Description

@proggeramlug

Perry's P1 migration had to leave outbound TCP clients on tokio because node:net's socket.upgradeToTLS hands a live, already-connected TcpStream to a TLS layer mid-stream (PostgreSQL's SSLRequest does exactly this, and Perry has a gap test for it). A turnloop socket owns its descriptor and exposes no way to get it back, in 0.1.0-alpha.2 or alpha.3, so the class of socket that might later be upgraded cannot start on turnloop at all — transport is fixed at creation.

Perry also cannot implement socket._handle.fd, which Node exposes.

Options to consider:

  1. Detached::into_fd() / into_handle(): detach a quiescent handle (the detach path already exists) and hand ownership of the raw descriptor back to the host, with the loop guaranteeing no outstanding operations.
  2. A borrowed accessor (as_raw_fd) with documented rules about concurrent operations, which is weaker but enough for socket._handle.fd.
  3. TLS on turnloop as the real answer for the upgrade case (Perry P5 uses turnloop-tls), leaving 1 or 2 for the general handoff.

Whichever is chosen must keep exactly-once completion and the buffer-ownership contract: a handle with pending operations must not be handed out, and after handoff the loop must not touch it. Windows needs the equivalent for sockets and named pipes, WASI and web return Unsupported.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions