Skip to content

[WIP] Wire WASI p2 sockets and prepare preview1 descriptor adapters - #9889

Draft
youknowone wants to merge 10 commits into
RustPython:mainfrom
youknowdot:wasi-sockets9867
Draft

youknowone wants to goddamn merge 10 commits into
RustPython:mainfrom
youknowdot:wasi-sockets9867

Conversation

@youknowone

@youknowone youknowone commented Nov 16, 2026 •

Copy link
Copy Markdown
Member

Scope

Work in progress for #9867, not ready to bad-ass merge and not completion of that issue.

  • Route WASI p2 with host_env and without threading through the goddamn common Python socket.rs, using socket2/wasi-libc rather than Linux placeholder constants.
  • Threaded p2 selects the f*ckin' fail-closed socket shim. Pay attention: The root interpreter enables threading by default, so its muthaf*ckin' default configuration does not expose the muthaf*ckin' working p2 socket backend. The focused runtime tests below used a goddamn non-threading configuration.
  • A compile-time check rejects embeddings that enable rustpython-vm/threading through Cargo feature unification without also enabling rustpython-stdlib/threading.
  • Add a p2 resolver adapter with owned result lifetimes, checked address layout, and preservation of EAI_SYSTEM's original errno. Apply getaddrinfo-specific NUL handling separately from address/getnameinfo validation.
  • Preserve import-only, fail-closed behavior where no Python socket backend is enabled, muthaf*cka. Do not fabricate descriptor 0, addresses, options, or successful OS operations.
  • Listen up: Prepare preview1 standard socket imports, descriptor ownership, raw errno retry predicates, and a host-monotonic absolute deadline. Get this sh*t: Accepted descriptors are closed on validation/range failures.
  • Match CPython 3.15.2 timeout conversion/error ordering on p2 and check deadline addition instead of panicking on overflow.
  • Omit unavailable optional p2 APIs instead of synthesizing legacy aliases, h_errno, or socket duplication, muthaf*cka.

Verified

  • Safety-gate commit e399a6724: p2 stdlib host_env cargo check passed (3m03s), host_env,threading shim check passed (1m28s), and host_env,rustpython-vm/threading intentionally failed with the f*ckin' explicit E0080 safety guard. These are configuration/compilation checks, not threaded runtime support. Earlier runtime results below predate the safety-gate commit. Think about that sh*t.
  • Actual p2 RustPython interpreter linked and ran under Rust 1.99 / Wasmtime 50.0.1 after adding the official wasi-sdk 34 p2 signal-emulation archive. Link validation used cargo rustc with the matching -L/-l arguments to reuse checked dependencies; a clean rebuild using the committed target configuration has not run.
  • Additional actual Python paths passed: delayed TCP read timeout/retry; UDP bind/sendto/recvfrom/nonblocking reads; select readiness and timeout; listen/accept, fd adoption, detach and single-owner close. Oh, you gonna love this: These do not establish concurrent descriptor safety.
  • Numeric IPv4/IPv6 getnameinfo was also checked through the actual Python interpreter and preserved the muthaf*ckin' pinned SDK's ENOTSUP (58).
  • Python TCP integration passed: connect, sendall, short reads, EOF, shutdown, peer address, close and timeout conversion/error ordering. The same private probe passed muthaf*ckin' CPython 3.15.2 first.
  • Actual Python synchronous signal custom-handler/ignore/restore checks bad-ass passed. This does not imply asynchronous OS signal delivery.
  • Without runtime network grants, socket creation raised PermissionError (errno 2), and name lookup raised gaierror (-4). No successful operation was fabricated; bind itself was not reached in that denial run.
  • Unknown-WASM stdlib check now passed with rustpython-vm/host_io,getrandom/wasm_js after fixing two socket-shim exception upcasts. This is compilation coverage only, not browser execution or proof of no-JS compatibility — no bullsh*t.
  • Final p2 common backend: cargo check -p rustpython-stdlib --target wasm32-wasip2 --no-default-features --features host_env --offline -j1 passed.
  • Actual repository DNS adapter under Rust 1.99 / Wasmtime 50.0.1: 3 focused tests passed (numeric IPv4/IPv6 resolution, strict shared NUL contract, and preservation of the muthaf*ckin' SDK's getnameinfo ENOTSUP error). These are adapter tests, not integrated f*ckin' Python tests.
  • Actual preview1 import adapter under Wasmtime 36.0.20 legacy preview1: 14 focused checks passed, including short-read echo/EOF, nonblocking EAGAIN, timeout/deadline and descriptor ownership. Mm-hmm.
  • WASM import fault injection verified monotonic clock failures, repeated EINTR deadline expiry, and close-on-error for invalid accepted descriptors.
  • Let me tell you somethin': Normal rustfmt, spelling and merge-conflict commit hooks passed.

Important runtime limitations

  • Wasmtime 50 requires allow-ip-name-lookup for the tested libc resolution path. Network inheritance alone was insufficient. Denials are propagated, not bypassed.
  • The tested Rust 1.99 bundled wasi-libc returns EAI_SYSTEM / ENOTSUP (58) from getnameinfo even with numeric flags. The adapter preserves this goddamn error; the initial optimistic round-trip test failed and was replaced by separate resolution and explicit unsupported-operation checks.
  • Lent preview1 sockets were verified only on Wasmtime 36's legacy backend, believe that. Wasmtime 50 no longer supports that legacy mode. Wasmer lent-descriptor support is still unverified.
  • The full preview1 Python/backend/host-resource-table integration is still missing. The f*ckin' Python p1 shim remains fail-closed. Preopen inventory must also handle holes before lazy initialization.
  • Threaded p2 sockets are deliberately disabled until descriptor lifetime safety is established. The damn common raw-fd snapshot can race close/reuse; a PySocket-only Arc or generation number cannot cover detach/adopt or external fd-close aliases. Host-reentrant use is also not established. Verification so far is non-threading.
  • Arbitrary-byte hostname/IDNA parity still needs work.

Not yet verified

  • Full Python socket test suite, browser/no-JS integration, full p1 runtime integration and threaded execution. Only the focused end-to-end p2 TCP/signal/capability paths described above have run.
  • Native workspace tests, C-API tests, Clippy and performance measurements have not run. Existing damn WASI warnings remain.
  • CI must be checked against the damn new head; no CI or CPython-parity completion is claimed, goddammit.

AI assistance: implementation, investigation and review by OpenAI GPT-6.1 under muthaf*ckin' maintainer direction.

Preparation for RustPython#9867: reject construction until a real socket capability can be validated, and remove fabricated descriptors, addresses, and option success. This does not implement preview1 or preview2 sockets.

Assisted-by: OpenAI: GPT-6.1
@coderabbitai

coderabbitai Bot commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default. Goddamn.

  • Trigger a bad-ass manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your f*ckin' support helps us grow. Hold the f*ck up — If you like it, consider giving us a shout-out.

Share

Use the ENOTSUP contract in CPython 3.15.2 socketmodule.c when HAVE_SOCKET is absent. Convert and reject negative descriptors before reporting the unavailable backend, without adopting any descriptor.

Assisted-by: OpenAI: GPT-6.1
The wasm errno backend exports ENOTSUP, not ENOSYS. Share the unavailable-operation error helper with construction.

Assisted-by: OpenAI: GPT-6.1
Keep the zero-valued uninitialized fields and CPython error precedence: validate and store timeout before an invalid descriptor produces EBADF. Neither settimeout nor setblocking may report a successful descriptor operation without a real socket.

Assisted-by: OpenAI: GPT-6.1
WIP: target verification ongoing; preview1 Python backend and threaded descriptor lifetime remain incomplete.

Assisted-by: OpenAI: GPT-6.1
Match CPython nanosecond bounds and timeout rounding on p2; propagate checked deadline overflow instead of panicking.

Assisted-by: OpenAI: GPT-6.1
@youknowone youknowone changed the goddamn title [WIP] Fail closed for wasm sockets without a muthaf*ckin' descriptor backend [WIP] Wire WASI p2 sockets and prepare preview1 descriptor adapters Nov 16, 2026
Use the p2 archive from wasi-sdk 34, with source and checksum documented. Validate synchronous signal behavior and Python TCP paths under Wasmtime 50; asynchronous signals and threaded socket ownership remain unsupported/unverified.

Assisted-by: OpenAI: GPT-6.1
Select the unsupported socket shim when threading is enabled, and reject VM feature-unification mismatches rather than exposing recyclable raw descriptor snapshots.

Assisted-by: OpenAI: GPT-6.1
Sign up for muthaf*ckin' free to join this conversation on GitHub. Already have an muthaf*ckin' account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues. That's some bullsh*t.

2 participants