Fix job unfreeze giving false negative when trying to unfreeze after killing the most recent job#16909
Fix job unfreeze giving false negative when trying to unfreeze after killing the most recent job#16909peachey2k2 wants to merge 2 commits intonushell:mainfrom
job unfreeze giving false negative when trying to unfreeze after killing the most recent job#16909Conversation
64b19c5 to
0d6ccb1
Compare
sholderbach
left a comment
There was a problem hiding this comment.
Thanks for looking into this. I am gonna ping @cosineblast if he has special remarks as our resident job expert :)
| pub struct FrozenJob { | ||
| pub unfreeze: UnfreezeHandle, | ||
| pub tag: Option<String>, | ||
| pub timestamp: DateTime<Utc>, |
There was a problem hiding this comment.
I am not sure if using chrono::DateTime is the best choice here. I don't think it has the monotonicity guarantees of std::time::Instant which should preserve the order of jobs even if you are messing with timezone or clock settings while a job is frozen.
If we don't need to directly present it to users having the support for timezones etc. would be overkill.
There was a problem hiding this comment.
Fair enough. My initial thought was to also show it to the users too, but figured that'd bloat the PR.
2d8e730 to
0b533b0
Compare
|
Looks good to me! |
|
Sorry for the insane amount of amends, I should have been more careful. I'm not very familiar with BTreeMap, but I'm guessing that'd mean faster reorders at the cost of more memory and doing more allocations. Either way, I doubt it'd make a difference, as almost no one will have enough jobs for it to matter. |
|
waiting for tests |
|
I've been looking into adding in the tests, but there's a problem. Let me explain: #[test]
fn job_unfreeze_works() {
let actual = nu!(r#"
nu -c "kill -s 19 $nu.pid; echo meep"
job unfreeze
"#);
assert!(actual.out.ends_with("meep"));
assert_eq!(actual.err, "");
}This is one of the tests I've written. 19 corresponds to SIGSTOP, which does the same thing as Ctrl+Z. In theory this should work, but it instead hangs and leaves the spawned nushell instance as a zombie process. But when I try the same lines on my terminal, it works perfectly: $ nu -c "kill -s 19 $nu.pid; echo meep"; job unfreeze
Job 1 is frozen
meepOf course, $ nu -c 'nu -c "kill -s 19 $nu.pid; echo meep"; job unfreeze'
Error: nu::shell::io::uncategorized_error
× I/O error
╰─▶ × Failed to unfreeze foreground process
╭────
1 │ crates/nu-command/src/experimental/job_unfreeze.rs:148:21
· ────────────────────────────┬────────────────────────────
· ╰── Uncategorized error
╰────
Error: nu::shell::non_zero_exit_code
× External command had a non-zero exit code
╭─[entry #4:1:1]
1 │ nu -c 'nu -c "kill -s 19 $nu.pid; echo meep"; job unfreeze'
· ─┬
· ╰── exited with code 1
╰────The issue is that I don't really know what the right approach would be in this case. Edit: I used |
|
@peachey2k2 can we get these conflicts resolved and move forward? |
…r killing the most recent job
|
Sorry for not checking formatting. Also I commented out the tests so beware of that. |
Changes
FrozenJobto store the timestamp of the last freeze.remove_job()to replace the last job ID with the most recently unfrozen job, instead of blindly erasing it.Fixes #16561