Skip to content

Add windows support on async #290

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Mar 31, 2025
Merged

Conversation

jprendes
Copy link
Contributor

@jprendes jprendes commented Mar 4, 2025

This PR adds Windows support to the async feature.
It introduces a transport layer with structs:

  • Socket: a thin wrapper around a boxed AsyncRead + AsyncWrite.
  • Listener: a thin wrapper around a boxed stream of Sockets

These struct have implementations for: uds, vsocks, and named pipes.

In the process, this PR also introduces some breaking change in the public API.

  • Client::connect is now async.
  • Client::new now takes a Socket instead of a RawFd.
    • The old behaviour is preserved in Client::from_raw_unix_listener_fd, which takes a RawFd and is marked unsafe.
  • Connection::new now takes a Socket instead of any AsyncRead + AsyncWrite
  • Server::add_listener now takes a Listener instead of a RawFd.
  • Server::set_domain_{unix,vsock} have been removed.
    • The old behavior is somewhat preserved in Client::add_{unix_vsock}_listener, which takes a RawFd and is marked unsafe.
  • Server doesn't implement AsRawFd or FromRawFd anymore.
  • TtrpcContext doesn't have an fd field anymore.

I think it would be possible to add Windows support without breaking the public API, but I believe the proposed changes make more sense while still providing an upgrade path.

@jprendes jprendes force-pushed the async-windows branch 11 times, most recently from 1641dbf to 2c3e9d0 Compare March 5, 2025 12:51
@jprendes jprendes marked this pull request as ready for review March 5, 2025 13:09
@jprendes jprendes requested a review from jsturtevant March 5, 2025 13:53
@jprendes
Copy link
Contributor Author

jprendes commented Mar 5, 2025

@Tim-Zhang PTAL

jprendes added 2 commits March 5, 2025 17:34
Add support for windows named pipes to the async codebase.
This refactor the codes to use a transport abstraction instead of file descriptors.

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Fix failure with deny workflow in CI.
This requires bumping cargo-deny-action, which introduces a breaking change in the syntax of deny.toml

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Copy link
Collaborator

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried it out on windows and it works!

jprendes added 2 commits March 5, 2025 23:38
The windows API for querying the named pipe path explicitly mentions that it shouldn't be used with pipes.
To avoid that, store the path of the pipe when binging it, and reuse that value.

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Improve the error message when a server is started with no listener specified

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@Tim-Zhang
Copy link
Member

@jprendes Thank you for your PR. The community has been waiting for this feature for a long time.
I am a bit busy these two weeks. @jsturtevant @wllenyj @lifupan @teawater Please take a look at this. thanks.

Copy link
Collaborator

@jsturtevant jsturtevant left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a look at the windows implementation and tried it out. The tests have also been enabled to run all the examples on Windows too (Thanks @jprendes!)

The rest of the refactoring look like an overall improvement to me as well but let the other maintainers decide on the changes there.

LGTM

Copy link
Collaborator

@wllenyj wllenyj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks!

@jprendes
Copy link
Contributor Author

Gentle ping :-) @Tim-Zhang
Please let me know if I can help moving this forward.

@jsturtevant
Copy link
Collaborator

@Tim-Zhang I think we are good here and is ready for your final approval

@Tim-Zhang
Copy link
Member

Hi @jprendes I tried to run the example async-stream with the command cargo run --example async-stream-client and I got the error:

called `Result::unwrap()` on an `Err` value: Others("Socket::connect error 系统找不到指定的文件。 (os error 2)")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\examples\async-stream-client.exe` (exit code: 101)

Is this expected behavior? Does this PR currently support async streams?

@jprendes
Copy link
Contributor Author

That's odd.
I run this on one terminal

cargo run --example async-stream-server

and this on another terminal

cargo run --example async-stream-client

and I get

cargo run --example async-stream-client
    Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.63s
     Running `target\debug\examples\async-stream-client.exe`
***** Async Stream test is OK! *****

@jprendes
Copy link
Contributor Author

I just noticed that I never enabled the async examples for windows in run_example, I'll push that

This commit enables on Windows the async examples in the run_examples test

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@jprendes
Copy link
Contributor Author

Looks like the streaming client is also working in CI
https://github.com/containerd/ttrpc-rust/actions/runs/14132937711/job/39597617179?pr=290#step:3:406

@Tim-Zhang
Copy link
Member

Hi @jprendes I tried to run the example async-stream with the command cargo run --example async-stream-client and I got the error:

called `Result::unwrap()` on an `Err` value: Others("Socket::connect error 系统找不到指定的文件。 (os error 2)")
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
error: process didn't exit successfully: `target\debug\examples\async-stream-client.exe` (exit code: 101)

Is this expected behavior? Does this PR currently support async streams?

@jprendes Sorry, I think it was a wrong bug report. Forget it please.

since transport.rs has submodules, move it from transport.rs to transport/mod.rs

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@Tim-Zhang Tim-Zhang added the BREAKING CHANGE Introduces a breaking API change label Mar 28, 2025
@Tim-Zhang Tim-Zhang linked an issue Mar 28, 2025 that may be closed by this pull request
Copy link
Member

@Tim-Zhang Tim-Zhang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, Thanks @jprendes

@Tim-Zhang Tim-Zhang merged commit 7ca128d into containerd:master Mar 31, 2025
12 checks passed
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 3, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 3, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 3, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 3, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 9, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request Apr 9, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The codegen crate needs a major version bump because it exports an item from the compiler crate.
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
@jprendes jprendes mentioned this pull request Apr 9, 2025
KarstenB pushed a commit to KarstenB/ttrpc-rust that referenced this pull request May 1, 2025
jprendes added a commit to jprendes/ttrpc-rust that referenced this pull request May 20, 2025
Bump crate versions for publishing.
The compiler crate needs a major version bump after breaking changes introduced by PR containerd#291
The codegen crate needs a major version bump because it exports an item from the compiler crate.
The main crate needs a major version bump after the braking changes introduced by PR containerd#290

Signed-off-by: Jorge Prendes <jorge.prendes@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
BREAKING CHANGE Introduces a breaking API change
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Windows support
4 participants