Skip to content

Return error when external command core dumped - #5908

Merged
fdncred merged 3 commits into
nushell:mainfrom
nibon7:coredump
Jul 1, 2022
Merged

fdncred merged 3 commits into
nushell:mainfrom
nibon7:coredump

Conversation

@nibon7

@nibon7 nibon7 commented Jun 29, 2022 •

Copy link
Copy Markdown
Contributor

Fixes #5903

Description

(description of your pull request here)

Tests

Make sure you've done the following:

  • Add tests that cover your changes, either in the command examples, the crate/tests folder, or in the /tests folder.
  • Try to think about corner cases and various ways how your changes could break. Cover them with tests.
  • If adding tests is not possible, please document in the PR body a minimal example with steps on how to reproduce so one can verify your change works.

Make sure you've run and fixed any issues with these commands:

  • cargo fmt --all -- --check to check standard code formatting (cargo fmt --all applies these changes)
  • cargo clippy --workspace --features=extra -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect to check that you're using the standard code style
  • cargo test --workspace --features=extra to check that all the tests pass

Comment thread crates/nu-command/Cargo.toml Resolved
Signed-off-by: nibon7 <[email protected]>
@fdncred

fdncred commented Jul 1, 2022

Copy link
Copy Markdown
Contributor

I'm having a hard time getting over the addition of 100ms blocking on every command.

@nibon7

nibon7 commented Jul 1, 2022 •

Copy link
Copy Markdown
Contributor Author

I'm having a hard time getting over the addition of 100ms blocking on every command.
Not every external command block 100ms :(

If stdout_tx.send() or stderr_tx.send() doesn't block, exit_status_rx.recv_timeout(Duration::from_millis(100)) shouldn't block 100ms except that child.wait() return an error.

/data/source/nushell〉git diff | more                                                                                                     07/01/2022 09:21:51 PM
>recv ok: took 3 ms
diff --git a/crates/nu-command/src/system/run_external.rs b/crates/nu-command/src/system/run_external.rs
index 35672f300..c854e0e89 100644
--- a/crates/nu-command/src/system/run_external.rs
+++ b/crates/nu-command/src/system/run_external.rs
@@ -317,7 +317,9 @@ impl ExternalCommand {
                     use std::time::Duration;

                     // The receiver will block 100ms if there's no sender
+                    let t = std::time::Instant::now();
                     if let Ok(status) = exit_status_rx.recv_timeout(Duration::from_millis(100)) {
+                        eprintln!(">recv ok: took {} ms", t.elapsed().as_millis());
                         if status.core_dumped() {
                             if let Some(sig) = status.signal().and_then(signal_name) {
                                 return Err(ShellError::ExternalCommand(
@@ -327,6 +329,8 @@ impl ExternalCommand {
                                 ));
                             }
                         }
+                    } else {
+                        eprintln!(">recv err: took {} ms", t.elapsed().as_millis());
                     }
                 }

>recv ok: took 0 ms
/data/source/nushell〉dmesg | head -n1                                                                                                    07/01/2022 09:21:57 PM
>recv err: took 100 ms
[    0.000000] Linux version 5.18.8 (root@yoga14s) (clang version 14.0.4, LLD 14.0.4) #7 SMP PREEMPT_DYNAMIC Thu Jun 23 13:36:15 CST 2022
>recv ok: took 0 ms
/data/source/nushell〉^ls /                                                                                                              07/01/2022 09:22:57 PM
bin  boot  data  dev  etc  home  lib  lib64  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
>recv ok: took 0 ms
/data/source/nushell〉^ls / | rg home                                                                                                    07/01/2022 09:23:08 PM
>recv ok: took 0 ms
home
>recv ok: took 7 ms

@fdncred

fdncred commented Jul 1, 2022

Copy link
Copy Markdown
Contributor

ok, that sounds more reasonable. thanks for explaining. let's give it a try.

@fdncred
fdncred merged commit 5d00ece into nushell:main Jul 1, 2022
@nibon7
nibon7 deleted the coredump branch July 2, 2022 02:29
@rgwood

rgwood commented Jul 7, 2022

Copy link
Copy Markdown
Contributor

I'm looking at this again in relation to #5960 and I think this was implemented incorrectly.

We spin up a background thread, and the exit status is sent from inside that thread. But the code that reads the exit status runs immediately after the background thread is started.

And so it seems like this code can only successfully check the exit status of a process that exits within ~100ms. Which isn't quite right - we should be able to get the exit status even if a process exits after running for a long time.

rgwood added a commit to rgwood/nushell that referenced this pull request Jul 7, 2022
rgwood added a commit that referenced this pull request Jul 8, 2022
@sholderbach sholderbach mentioned this pull request Oct 20, 2022
5 of 7 tasks
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.

Nushell won't show segmentation fault (core dumped

3 participants