Skip to content
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

chore(example): Autoreloading server example #316

Merged
merged 4 commits into from
Apr 9, 2020

Conversation

thisKai
Copy link
Contributor

@thisKai thisKai commented Apr 1, 2020

Motivation

I was trying to figure out whether the trick actix-web uses for autoreloading the server would work with tonic. All that was needed was to add listenfd as a dependency, install systemfd, change the following code:

Server::builder()
        .add_service(GreeterServer::new(greeter))
        .serve(addr)
        .await?;

to:

let server = Server::builder()
    .add_service(GreeterServer::new(greeter));

match listenfd::ListenFd::from_env().take_tcp_listener(0)? {
    Some(listener) => {
        let mut listener = tokio::net::TcpListener::from_std(listener)?;

        server.serve_with_incoming(listener.incoming()).await?;
    }
    None => {
        server.serve(addr).await?;
    }
}

and run:

systemfd --no-pid -s http::$ADDRESS_OR_PORT -- cargo watch -x run

Solution

I created an example with a copy of the helloworld server with these modifications, added listenfd as a dependency of the examples repository and added notes to the examples readme

@LucioFranco
Copy link
Member

This seems like a good addition! I have a PR to fix the deny #319 then we can merge this once you mark this as ready for review!

@thisKai
Copy link
Contributor Author

thisKai commented Apr 4, 2020

Thanks! I was hoping this would be useful to someone, I'm happy to mark it as ready since there's only one red cross left to get rid of

@thisKai thisKai marked this pull request as ready for review April 4, 2020 00:13
@LucioFranco
Copy link
Member

@thisKai so just one question, does this work on windows? I am not super familiar with listenfd.

Looks like the CI check will pass if you rebase against master I believe.

@thisKai
Copy link
Contributor Author

thisKai commented Apr 9, 2020

I think so, I'll check now

@thisKai
Copy link
Contributor Author

thisKai commented Apr 9, 2020

It works, I'll rebase it now

@thisKai thisKai force-pushed the autoreload-example branch from 66dc49e to 059ba50 Compare April 9, 2020 21:19
@LucioFranco
Copy link
Member

Thanks!

@LucioFranco LucioFranco changed the title Autoreloading server example chore(example): Autoreloading server example Apr 9, 2020
@LucioFranco LucioFranco merged commit f6ecaff into hyperium:master Apr 9, 2020
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.

2 participants