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

Salvo Support #247

Closed
gustavocadev opened this issue Feb 8, 2023 · 15 comments
Closed

Salvo Support #247

gustavocadev opened this issue Feb 8, 2023 · 15 comments

Comments

@gustavocadev
Copy link

gustavocadev commented Feb 8, 2023

I've noticed that currently cargo-watch doesn't support Salvo web framework because when I use it with Salvo it doesnt work at all

  • A debug log
    Screen Shot 2023-02-08 at 9 40 46 AM
    As I have said below, the terminal simply freezes up

  • Command I'm running

cargo watch -x run
  • What I'm expecting to happen
    I'm expecting cargo watch will do a normal hot reload

  • What's happening instead?
    The terminal froze and every time I make a change it does nothing and stays frozen.

  • OS
    macOS Monterrey 12.6.3
    Rust: 1.67.0

  • How you installed Cargo Watch.

cargo install cargo-watch
@passcod
Copy link
Member

passcod commented Feb 8, 2023

Hi Gustavo

To do anything at all about this, I would need:

  • A debug log
  • A command you're running
  • What you're expecting to happen
  • What's happening instead. In detail.
  • The OS you're running on.
  • How you installed Cargo Watch.

That is the minimal amount of information that's needed for this, and frankly any bug report to a project. Without it I hope you understand that I'll have to close this issue as unactionable.

Thank you

@gustavocadev
Copy link
Author

gustavocadev commented Feb 8, 2023

Hi Gustavo

To do anything at all about this, I would need:

  • A debug log
  • A command you're running
  • What you're expecting to happen
  • What's happening instead. In detail.
  • The OS you're running on.
  • How you installed Cargo Watch.

That is the minimal amount of information that's needed for this, and frankly any bug report to a project. Without it I hope you understand that I'll have to close this issue as unactionable.

Thank you

Ready, I've done it 👍

@passcod
Copy link
Member

passcod commented Feb 8, 2023

That's not a debug log. That's an incomplete picture from your terminal.

cargo watch --debug -x run

What happens if you run cargo run on its own?

One thing I notice, for example, is that if I put the salvo hello world in a project and run it, it produces no output at all. It's working, it just says nothing. As a consequence, running cargo watch exhibits the same behaviour.


As a note, try not to edit your post over and over? That just means that I can't see when you change the text and the details change. For example, this sentence:

The terminal froze and every time I make a change it does nothing and stays frozen.

Wasn't there when I started writing this post. Now I really need that debug log. Please provide it as text, not as pictures.


Please also note that cargo watch restarts the whole process, it does not do a "hot reload". I'm unsure if salvo has a facility for hot reloading -- if it does, you probably want to use that instead.


Finally, my suspicion at this point is that this is an issue introduced by a recent macOS upgrade. Anecdotally, downgrading to cargo watch 8.1.1 may help:

cargo install cargo-watch@8.1.1

@gustavocadev
Copy link
Author

gustavocadev commented Feb 8, 2023

cargo watch --debug -x run

cargo_watch::root: 2023-02-08T11:15:08.840-05:00 - DEBUG - change directory to: /Users/tree/Desktop/rust-salvo
cargo_watch::options: 2023-02-08T11:15:08.841-05:00 - DEBUG - Load Git/VCS ignores: true
cargo_watch::options: 2023-02-08T11:15:08.841-05:00 - DEBUG - Load .ignore ignores: true
cargo_watch::options: 2023-02-08T11:15:08.841-05:00 - DEBUG - Default ignores: ["*/.DS_Store", "*.sw?", "*.sw?x", "#*#", ".#*", ".*.kate-swp", "*/.hg/**", "*/.git/**", "*/.svn/**", "*.db", "*.db-*", "*/*.db-journal/**", "*/target/**"]
cargo_watch::options: 2023-02-08T11:15:08.841-05:00 - DEBUG - All ignores: ["*/.DS_Store", "*.sw?", "*.sw?x", "#*#", ".#*", ".*.kate-swp", "*/.hg/**", "*/.git/**", "*/.svn/**", "*.db", "*.db-*", "*/*.db-journal/**", "*/target/**"]
cargo_watch::options: 2023-02-08T11:15:08.842-05:00 - DEBUG - File updates debounce: 0.5 seconds
cargo_watch::options: 2023-02-08T11:15:09.902-05:00 - DEBUG - Watches: ["/Users/tree/Desktop/rust-salvo", "."]
cargo_watch::options: 2023-02-08T11:15:09.902-05:00 - DEBUG - Commands: ["cargo run"]
cargo_watch::options: 2023-02-08T11:15:09.904-05:00 - DEBUG - Watchexec arguments: Config { cmd: ["cargo run"], paths: ["/Users/tree/Desktop/rust-salvo", "."], filters: [], ignores: ["*/.DS_Store", "*.sw?", "*.sw?x", "#*#", ".#*", ".*.kate-swp", "*/.hg/**", "*/.git/**", "*/.svn/**", "*.db", "*.db-*", "*/*.db-journal/**", "*/target/**"], clear_screen: false, signal: None, on_busy_update: Restart, debounce: 500ms, run_initially: true, shell: Unix("sh"), no_meta: false, no_environment: true, no_vcs_ignore: false, no_ignore: false, once: false, poll: false, poll_interval: 500ms, use_process_group: true }
watchexec::gitignore: 2023-02-08T11:15:09.995-05:00 - DEBUG - Looking in "/Users/tree/Desktop/rust-salvo" for a .git directory
watchexec::gitignore: 2023-02-08T11:15:09.995-05:00 - DEBUG - Found the top level git directory: "/Users/tree/Desktop/rust-salvo"
globset: 2023-02-08T11:15:10.016-05:00 - DEBUG - glob converted to regex: Glob { glob: "target/**", re: "(?-u)^target(?:/?|/.*)$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true }, tokens: Tokens([Literal('t'), Literal('a'), Literal('r'), Literal('g'), Literal('e'), Literal('t'), RecursiveSuffix]) }
globset: 2023-02-08T11:15:10.016-05:00 - DEBUG - built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
watchexec::gitignore: 2023-02-08T11:15:10.018-05:00 - DEBUG - Loaded "/Users/tree/Desktop/rust-salvo/.gitignore"
watchexec::gitignore: 2023-02-08T11:15:10.018-05:00 - DEBUG - Looking in "/Users/tree/Desktop/rust-salvo" for a .git directory
watchexec::gitignore: 2023-02-08T11:15:10.018-05:00 - DEBUG - Found the top level git directory: "/Users/tree/Desktop/rust-salvo"
globset: 2023-02-08T11:15:10.036-05:00 - DEBUG - glob converted to regex: Glob { glob: "target/**", re: "(?-u)^target(?:/?|/.*)$", opts: GlobOptions { case_insensitive: false, literal_separator: true, backslash_escape: true }, tokens: Tokens([Literal('t'), Literal('a'), Literal('r'), Literal('g'), Literal('e'), Literal('t'), RecursiveSuffix]) }
globset: 2023-02-08T11:15:10.036-05:00 - DEBUG - built glob set; 0 literals, 0 basenames, 0 extensions, 0 prefixes, 0 suffixes, 0 required extensions, 1 regexes
watchexec::gitignore: 2023-02-08T11:15:10.036-05:00 - DEBUG - Loaded "/Users/tree/Desktop/rust-salvo/.gitignore"
watchexec::notification_filter: 2023-02-08T11:15:10.037-05:00 - DEBUG - Adding ignore: "*/.DS_Store/**"
watchexec::notification_filter: 2023-02-08T11:15:10.037-05:00 - DEBUG - Adding ignore: "*.sw?/**"
watchexec::notification_filter: 2023-02-08T11:15:19.319-05:00 - DEBUG - Ignoring "/Users/tree/Desktop/rust-salvo/target/debug/.fingerprint/rust-salvo-75745f4afab261a2/bin-rust-salvo": matched ignore filter
watchexec::notification_filter: 2023-02-08T11:15:19.320-05:00 - DEBUG - Ignoring "/Users/tree/Desktop/rust-salvo/target/debug/.fingerprint/rust-salvo-75745f4afab261a2/bin-rust-salvo.json": matched ignore filter
     Running `target/debug/rust-salvo`
Server running at port 3000
watchexec::run: 2023-02-08T11:15:43.173-05:00 - INFO - Paths updated: [PathOp { path: "/Users/tree/Desktop/rust-salvo/src/main.rs", op: Some((empty)), cookie: None }, PathOp { path: "/Users/tree/Desktop/rust-salvo/src/main.rs", op: Some(WRITE), cookie: None }]
[Running 'cargo run']
watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - ON UPDATE: called
watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - ON UPDATE: has_running_processes: true --- on_busy_update: Restart
watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - Sending signal SIGTERM to process group id=70738

@gustavocadev
Copy link
Author

As a note, try not to edit your post over and over? That just means that I can't see when you change the text and the details change. For example, this sentence:

Oh Sorry about that, that's not what I meant to do

@gustavocadev
Copy link
Author

cargo install cargo-watch@8.1.1

I just tested it, the same behavior occurs

@passcod
Copy link
Member

passcod commented Feb 8, 2023

Well, from the log we can see that cargo watch is working. It's starting your server, and your server is listening.

[Running 'cargo run']
Finished dev [unoptimized + debuginfo] target(s) in 9.19s
Running `target/debug/rust-salvo`
Server running at port 3000

Presumably you're then modifying something, and we can see cargo watch also responding to that:

watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - ON UPDATE: called
watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - ON UPDATE: has_running_processes: true --- on_busy_update: Restart
watchexec::run: 2023-02-08T11:15:43.173-05:00 - DEBUG - Sending signal SIGTERM to process group id=70738

It's sending a SIGTERM to your process.

As that's the end of your log, I'm assuming that the process then "freezes".

Are you by any chance handling signals in your app? If you're not responding to SIGTERM by quitting, then that would behave like you're seeing.

@gustavocadev
Copy link
Author

Are you by any chance handling signals in your app? If you're not responding to SIGTERM by quitting, then that would behave like you're seeing.

You're right, but I don't handle any signal in my app, not sure how to do it
My app code is basically this:

use salvo::prelude::*;

#[handler]
async fn hello_world(res: &mut Response) {
  res.render(Text::Plain("Hello world!"));
}

#[tokio::main]
async fn main() {
  let router = Router::with_path("/").get(hello_world);

  println!("Server running at port 3000");
  Server::new(TcpListener::bind("127.0.0.1:3000"))
    .serve(router)
    .await;
}

@julienfouilhe
Copy link

I have the same problem with my tonic grpc server, same logs "Sending signal SIGTERM to process group id" and then it hangs.
Running the cargo run command manually and sending a SIGTERM to that process works fine, the server quits as expected.

i'm on macOS Ventura running cargo-watch@8.3.0. Also same behavior on 8.1.1.

[Running 'cargo run --features reflection --bin grpc']
watchexec::run: 2023-02-08T23:01:34.660+01:00 - DEBUG - Assembled command: "sh" "-c" "cargo run --features reflection --bin grpc; echo \"[Finished running. Exit status: $?]\""
watchexec::run: 2023-02-08T23:01:34.660+01:00 - DEBUG - Launching command
watchexec::run: 2023-02-08T23:01:34.663+01:00 - DEBUG - Waiting for filesystem activity
    Finished dev [unoptimized + debuginfo] target(s) in 0.16s
     Running `/Users/julien/cash/backend/target/debug/grpc`
Enabling reflection for gRPC server
Listening on  port 3002...
watchexec::run: 2023-02-08T23:01:44.667+01:00 - INFO - Paths updated: [PathOp { path: "/Users/julien/cash/backend/apps/banking/src/presentation/grpc/mod.rs", op: Some(WRITE), cookie: None }]
[Running 'cargo run --features reflection --bin grpc']
watchexec::run: 2023-02-08T23:01:44.667+01:00 - DEBUG - ON UPDATE: called
watchexec::run: 2023-02-08T23:01:44.667+01:00 - DEBUG - ON UPDATE: has_running_processes: true --- on_busy_update: Restart
watchexec::run: 2023-02-08T23:01:44.667+01:00 - DEBUG - Sending signal SIGTERM to process group id=59828

@passcod
Copy link
Member

passcod commented Feb 8, 2023

mmkay, can you use watchexec and see how that behaves? If the issue persists, try with --no-process-group

@julienfouilhe
Copy link

@passcod watchexec -r -e rs -- cargo run --bin grpc works as expected, it kills the previous process and starts a new one

This doesn't work though

watchexec -e rs --on-busy-update signal -s SIGTERM -v --print-events -- cargo run --features reflection --bin grpc
[EVENT 0] Event
   Compiling banking v0.1.0 (/Users/julien/cash/backend/apps/banking)
    Finished dev [unoptimized + debuginfo] target(s) in 5.96s
     Running `/Users/julien/cash/backend/target/debug/grpc`
Enabling reflection for gRPC server
Listening on port 8888...
[EVENT 0] Event source=Filesystem kind=Modify(Metadata(Any)) path=/Users/julien/cash/backend/apps/banking/src/presentation/grpc/mod.rs filetype=file
[EVENT 1] Event source=Filesystem kind=Modify(Data(Content)) path=/Users/julien/cash/backend/apps/banking/src/presentation/grpc/mod.rs filetype=file
2023-02-08T22:29:37.932110Z ERROR watchexec::command::supervisor: while waiting on process err=io(waiting on process group): blocking waitpid returned pid=0
2023-02-08T22:29:37.932166Z ERROR watchexec::watchexec: runtime error err=io(waiting on process group): blocking waitpid returned pid=0
2023-02-08T22:29:37.932200Z ERROR watchexec_cli::config::init: io(waiting on process group): blocking waitpid returned pid=0

no-process-group doesn't work either.

@passcod
Copy link
Member

passcod commented Feb 12, 2023

Hey @julienfouilhe @gustavocadev could you try using Rust 1.65 to install cargo-watch and try again? It might be this issue: #249

@gustavocadev
Copy link
Author

gustavocadev commented Feb 12, 2023

Hey @julienfouilhe @gustavocadev could you try using Rust 1.65 to install cargo-watch and try again? It might be this issue: #249

oh yes, It works now, something must have changed in the latest version of Rust I guess, thanks, should I close this issue? I thought it was a thing about Salvo, but it seems something more general, Who would've thought

@passcod
Copy link
Member

passcod commented Feb 12, 2023

Yeah baffling issue. I'll close in favour of the other issue.

@passcod passcod closed this as completed Feb 12, 2023
@passcod
Copy link
Member

passcod commented Feb 15, 2023

Fixed in 8.4.0 and also in Watchexec 1.21.1

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

No branches or pull requests

3 participants