tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.54k stars 2.58k forks source link

sidecar node backend is running in background #8689

Open abhijitpatil181171 opened 10 months ago

abhijitpatil181171 commented 10 months ago

Describe the bug

I have create exe of react application where i have added node-sqlite backend as sidecar. when i run exe and close it using × it is closing exe as well as backend and working fine. i have scenerio where i am using this exe with node sidecar opened into autocad pallete window in which i run exe through code and open into pallete .now when i close pallete my exe is closing but node backend is still running in background . how can i close stop backend exe also when i stop my app exe.

Reproduction

No response

Expected behavior

when i close autocad pallete both app exe and side exe should close .

Full tauri info output

#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")]
use tauri::{
  api::process::{Command, CommandEvent},
  Manager,
};

fn main() {
  tauri::Builder::default()
  .setup(|app| {
  let window = app.get_window("main").unwrap();
  tauri::async_runtime::spawn(async move {
    // `new_sidecar()` expects just filename, NOT whole path like JavaScript
    let (mut rx, mut child) = Command::new_sidecar("node-sqlite-backend")

    .expect("failed to create `my-sidecar` binary command")
    .spawn()
    .expect("Failed to spawn sidecar");

    while let Some(event) = rx.recv().await {
      if let CommandEvent::Stdout(line) = event {
        println!("Stdout: {}", line);
        window
          .emit("message", Some(format!("'{}'", line)))
          .expect("failed to emit event");
        // write to stdin
        child.write("message from Rust\n".as_bytes()).unwrap();
      }
    }
  });
    Ok(())
  })
  .run(tauri::generate_context!())
  .expect("error while running tauri application");
}

this is my main.rs code where i am added my backend binary as sidecar

Stack trace

No response

Additional context

No response

naman-crabnebula commented 9 months ago

Well, that seems to be an interesting bug, although I am not sure whether it is bug with autocad pallete or Tauri, because if the sidecar is running even after closing pallete and the Tauri app, it might even be counted as a MEMORY LEAK and an Orphan process.

shirshak55 commented 2 days ago

@naman-crabnebula

I am facing same issue in windows

When I close tauri from taskbar the node process isn't closing.


tauri::Builder::default()
.setup(|app|) {

let sidecar_command = app.shell().sidecar("node").unwrap().args(["output.cjs"]);

let (mut rx, mut _child) = sidecar_command.spawn().unwrap()

....

It isn't closing automatically. I copy node js exe file and used that in external bin.