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

Starting fish background job in an event/variable handler borks commandline for duration of job #7842

Closed
IlanCosman opened this issue Mar 20, 2021 · 10 comments
Labels
bug Something that's not working as intended
Milestone

Comments

@IlanCosman
Copy link
Contributor

IlanCosman commented Mar 20, 2021

fish, version 3.2.1-5-gd79f86407
Tested on MacOS and Arch

not-highlighting.mp4
function on_foo --on-event foo
    fish --command "sleep 3" &
end

Syntax highlighting will be disabled for the full duration of the background job, i.e if you replace sleep 3 with sleep 10 it'll take 10 seconds to come back instead.

This also happens with --on-variable, and I presume all other handlers though I haven't tested them.

Interestingly this bug doesn't appear when running other commands such as sleep or kill, it only seems to work with fish.

Not sure if this is a regression.

@IlanCosman IlanCosman changed the title Starting fish background job in an event/variable handler disables highlighting for duration of job Starting fish background job in an event/variable handler borks commandline for duration of job Mar 21, 2021
@faho faho closed this as completed in e4fd664 Mar 21, 2021
@faho faho added the regression Something that used to work, but was broken, especially between releases label Mar 21, 2021
@faho faho added this to the fish 3.3.0 milestone Mar 21, 2021
@IlanCosman
Copy link
Contributor Author

@faho Is there anything I can do right now with fish script to remove this problem? Fish 3.3 might be a while and this is an annoying bug in my project 😄

faho added a commit that referenced this issue Mar 22, 2021
As it turns out otherwise fish would hang when sddm starts it as the login shell.

Belongs to #7842.
@faho
Copy link
Member

faho commented Mar 22, 2021

@IlanCosman I'll leave you in the capable hands of the others, I'm taking a break.

@IlanCosman
Copy link
Contributor Author

@ridiculousfish 😅 Sorry to bother, but would you happen to know a fancy Fish trick to get around this?

@krobelus
Copy link
Member

krobelus commented Mar 23, 2021

@IlanCosman on Linux you can use setsid to launch the background fish in a new process group.
Since it doesn't own the terminal 013a563 does the job.

function on_foo --on-event foo
    setsid fish --command "sleep 3" &
end

I'm not sure about which portable solution is best. Apparently nohup works as well instead of setsid.

@IlanCosman
Copy link
Contributor Author

Huh, it seems simply setting status job-control full fixes this. Sick!

@faho
Copy link
Member

faho commented Mar 26, 2021

Huh, it seems simply setting status job-control full fixes this. Sick!

@IlanCosman That is emphatically not a knob you want to touch (to be honest it should not exist to begin with, but we're working on that).

Instead simply set the background process's stdin to /dev/null:

    fish --command "sleep 3" </dev/null &

Since the issue is that fish only checks if the group controlling the stdin terminal is its group, just make it so that stdin isn't a terminal.

@IlanCosman
Copy link
Contributor Author

Thanks a ton @faho! Yah, setting the job-control was a bit sketchy, I noticed it was setting the user's last_pid outside of Tide but decided that minimal risk was an ok tradeoff.

This is why you can't take a break Fabian, I need you too much ❤️😂

dynamotn added a commit to dynamo-make-color/fish-canaudua that referenced this issue Mar 28, 2021
@zanchey zanchey added bug Something that's not working as intended and removed regression Something that used to work, but was broken, especially between releases labels Apr 1, 2021
@zanchey
Copy link
Member

zanchey commented Apr 1, 2021

This reproduces for me in 3.2.1, so I don't think it's a regression.

@faho
Copy link
Member

faho commented Apr 1, 2021

It's a regression from 3.2.0, caused by 013a563

@zanchey zanchey modified the milestones: fish 3.3.0, fish 3.2.2 Apr 1, 2021
@zanchey
Copy link
Member

zanchey commented Apr 1, 2021

OK, I'd prefer to keep the regression tag for "things that aren't in a release" as it means I can skip over them for the release notes.

zanchey pushed a commit that referenced this issue Apr 1, 2021
013a563 made it so we only try to
adjust terminal modes if we are in the terminal pgroup, but that's not
enough.

Fish starts background jobs in events inside its own pgroup, so

    function on-foo --on-event foo
        fish -c 'sleep 3' &
    end

would have the backgrounded fish try to fiddle with the terminal and
succeed.

Instead, only fiddle with the terminal if we're interactive (this
should probably be extended to other bits, but this is the particular
problematic part)

Fixes #7842.

(cherry picked from commit e4fd664)
zanchey pushed a commit that referenced this issue Apr 1, 2021
As it turns out otherwise fish would hang when sddm starts it as the login shell.

Belongs to #7842.

(cherry picked from commit 7f7cfcf)
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something that's not working as intended
Projects
None yet
Development

No branches or pull requests

4 participants