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

[bug] Receiver coming from Command::spawn() never gets stdout if child process uses output clearing #3508

Closed
JohannesKlauss opened this issue Feb 18, 2022 · 5 comments
Assignees

Comments

@JohannesKlauss
Copy link

Describe the bug

When using the sidecar to execute long running sub commands, I try to receive new stdout events.

For that I wrote this code:

let (mut rx, mut child) = cmd.spawn().expect("Failed to spawn sidecar");

tauri::async_runtime::spawn(async move {
    // read events such as stdout
    while let Some(event) = rx.recv().await {
        if let CommandEvent::Stdout(line) = event {
            debug!("{}", line);
            window.emit("upload-progress", Payload {
                message: line,
            });
        }
    }
    debug!("upload complete");
    window.emit("upload-complete", {});
});

But the future of rx.recv() is never resolved when spawning a command that clears its output before writing to it again (i.e. human readable progress in a terminal). It only resolves after the child process exited and then it dumps out all the lines at once.

Using a command that doesn't clear out before updating works fine and it seems like, that it also works fine when the command clears out and writes multiple lines.

I encountered that using the rclone sync source:path target:path --progress --progress-terminal-title --stats-one-line command.

Reproduction

  1. Create an app
  2. Using sidecar, spawn a long running command that always clears stdout before writing to it
  3. Try to receive events from command
  4. rx.recv().await doesn't resolve
  5. Wait until command finsihed
  6. rx.recv().await resolved with the complete output

Expected behavior

rx.recv().await should resolve for every event during running command

Platform and versions

Operating System - Mac OS, version 11.6.0 X64

Node.js environment
  Node.js - 16.13.0
  @tauri-apps/cli - 1.0.0-rc.4
  @tauri-apps/api - 1.0.0-rc.1

Global packages
  npm - 8.1.0
  pnpm - Not installed
  yarn - 1.22.10

Rust environment
  rustup - 1.24.3
  rustc - 1.58.1
  cargo - 1.58.0
  toolchain - stable-x86_64-apple-darwin 

App directory structure
/test
/dist
/node_modules
/src-tauri
/.git
/.idea
/src

App
  tauri - 1.0.0-rc.2
  tauri-build - 1.0.0-rc.2
  tao - 0.6.2
  wry - 0.13.1
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - ../dist
  devPath - http://local-desktop.syra.live:3000/
  framework - React
✨  Done in 9.42s.

Stack trace

No response

Additional context

Discussion with @FabianLars about that here in discord: https://discord.com/channels/616186924390023171/731495047962558564/944267064175132732

@lucasfernog
Copy link
Member

Did you try reading stderr instead of stdout @JohannesKlauss ? I know some CLIs use stderr for progress indicators.

@JohannesKlauss
Copy link
Author

Yes I tried, I actually also tried _ to match or just trying to assign a variable to rx.recv().await. It never resolves.

@nothingismagick
Copy link
Sponsor Member

Also note that during RC we are very rapidly releasing new patch type versions. To whit, your versions seem outdated.

@lucasfernog lucasfernog self-assigned this Feb 19, 2022
@lucasfernog
Copy link
Member

Seems like the issue happens because we're setting both stderr and stdout to the os_pipe::pipe() return value (removing the command.stderr(stderr_writer) one fixes it). I'll see if there's a way around it.

@lucasfernog
Copy link
Member

Opened oconnor663/duct.rs#102 let's see if there's a fix for this. I feel we might need to merge stderr and stdout :(

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants