Skip to content

stty in your config.fish causes externally backgrounded fish instances to stop #5246

Closed

Description

@jorgebucaran

Using stty in your config.fish causes background processes to suddenly stop.

To reproduce the issue add to your config.fish the following code.

stty werase undef

Then send any job to the background using &.

$ fish -c "echo" &
Job 1, 'fish -c "echo" &' has stopped

Running jobs tells me:

Job	Group	State	Command
1	83624	stopped	fish -c "echo" &

I can bring the process to the foreground using fg to finish it.

$ fg
Send job 1, 'fish -c "echo" &' to foreground
stty: tcsetattr: Interrupted system call

I know that wrapping the stty command like so:

if status --is-interactive
    ...
end

...will prevent the issue, but it's unfriendly to tell people how to write their configuration.

This issue was discovered by @tyilo while using jorgebucaran/fisher (see jorgebucaran/fisher#469). The presence of stty in their configuration causes fisher to hang because fisher keeps waiting for a process that is stopped.

I've been able to reproduce this issue on macOS, Linux (Arch) / xterm-256color running fish 2.0.0, 2.2.0, 2.7.1, and the latest fish from HEAD.

Activity

  1. mqudsi commented on Oct 11, 2018

    @mqudsi
    Contributor

    This is unfortunate since explicitly using stty in config.fish is the current workaround to #2980.

    As an aside, the title made me understand that it breaks background jobs within the session, not externally backgrounded fish runs.

  2. changed the title [-]stty in your config.fish causes background processes to suddenly stop[/-] [+]stty in your config.fish causes in-session background processes to suddenly stop[/+] on Oct 11, 2018
  3. jorgebucaran commented on Oct 11, 2018

    @jorgebucaran
    Author

    Thanks for having a look @mqudsi. I've updated the title.

  4. changed the title [-]stty in your config.fish causes in-session background processes to suddenly stop[/-] [+]stty in your config.fish causes externally backgrounded fish instances to stop[/+] on Oct 13, 2018
  5. added
    bug
    on Oct 21, 2018
  6. added this to the fish-future milestone on Oct 21, 2018
  7. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    It's not stty, it's anything that needs to read/write from/to the terminal. Adding cat to your config.fish and then trying to run it in the background does the same.

    I'm not sure this is a bug? It's a backgrounded process (i.e. a process that does NOT have control of the terminal) trying to access the terminal, it's going to SIGTTOU or SIGTTIN until it's brought to the foreground and given control of the shell. What do you expect to happen?

  8. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    Additionally, this is really independent of config.fish, even. Try running fish -c 'cat' & in a terminal, and you'll see the same behavior:

    mqudsi@Blitzkrieg /m/d/G/iMessage> fish -c 'cat' &
    Job 1, 'fish -c 'cat' &' has stopped
    

    or even bash:

    mqudsi@Blitzkrieg /m/d/G/iMessage> bash -c 'cat' &
    Job 1, 'bash -c 'cat' &' has stopped
    
  9. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @mqudsi The backgrounded process is not created in config.fish.

  10. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    I don't understand, can you explain what you mean? stty is being run as part of the background fish instance, isn't it?

  11. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    This issue was discovered by @tyilo with Fisher (see jorgebucaran/fisher#469). The presence of stty in their configuration causes fisher to hang because fisher keeps waiting for a process that is stopped.

    Fisher is not doing anything with stty. Fisher forks fish in the background for each package is trying to download, enabling concurrent downloads.

    The problem is the user is/was using stty in their config.fish. And using stty in config.fish will cause backgrounded fish instances to stop / hang.

    cc @mqudsi

  12. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @mqudsi It's not stty, it's anything that needs to read/write from/to the terminal.

    Thanks for the clarification. Is there any way to solve this? Should I tell users (albeit less casually) "Please do not put stty in your config.fish or something along those lines?

  13. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    @jorgebucaran I just want to make sure you're clear that it's not strictly an "stty in config.fish" issue. Any process that attempts to modify or read from the terminal is going to run into the same issue, although perhaps stty is special because people don't realize it's doing if they're not clear on how it works internally.

    @faho @zanchey @ridiculousfish just a thought here, but what if we started shipping config.fish with something like the following:

    # Place general fish and environment configuration here:
    
    # Anything beyond this point is not executed when fish isn't run interactively, 
    # such as via `fish -c '...'`
    if not status --is-interactive
        exit
    end
    
    # Place any external commands or commands modifying the behavior of terminal IO here
  14. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @mqudsi Once again thanks for the clarification :)

  15. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    @jorgebucaran why don’t you fork fish without a home directory or with a known configuration? That way you don’t need to work about the user doing anything untoward.

  16. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @mqudsi ...why don’t you fork fish without a home directory or with a known configuration?

    How? 👀

    Maybe that'll create new problems, but it's worth looking into.

  17. faho commented on Oct 31, 2018

    @faho
    Member

    @faho @zanchey @ridiculousfish just a thought here, but what if we started shipping config.fish with something like the following:

    I've considered not reading configuration if we're not interactive, but that would probably break the fisher code here (if it uses a function defined in a snippet).

    Even if we added that bit, I don't think users will get that stty touches the terminal, or that touching the terminal is bad if you're in the background. I don't think this particular user even knew what that was - this specific invocation did precisely nothing in fish.

    So that warning about "terminal IO" won't really help much.

  18. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @faho ...that would probably break the fisher code here (if it uses a function defined in a snippet).

    Could you elaborate a bit more? I'm don't see why. 🤔

    I don't think this particular user even knew what that was - this specific invocation did precisely nothing in fish.

    Actually, in all this time, I never took a moment to ask @tyilo: why where you using stty in your config.fish? Just curious.

    Perhaps he had a valid use case?

  19. faho commented on Oct 31, 2018

    @faho
    Member

    Could you elaborate a bit more? I'm don't see why. thinking

    If we don't source the configuration - neither config.fish, nor conf.d snippets - then you can't use the functions and variables defined there. So you'd be restricted in the kind of thing you could call in fish -c.

    Perhaps he had a valid use case?

    Because that call is something that's useful in bash. My guess is they just copied it over.

  20. jorgebucaran commented on Oct 31, 2018

    @jorgebucaran
    Author

    @faho ... nor conf.d snippets

    Interesting. I didn't know this would mean not sourcing configuration snippets.

  21. mqudsi commented on Oct 31, 2018

    @mqudsi
    Contributor

    Yes, my idea was to explicitly skip the configuration file then source a "fisher jail configuration" that would allow you to set up an environment that would do what you need and load any functions, etc. necessary to proceed with the operation. It's more work to get started but it'd be entirely deterministic.

  22. jorgebucaran commented on Nov 1, 2018

    @jorgebucaran
    Author

    @mqudsi why don’t you fork fish without a home directory or with a known configuration?

    How?

  23. mqudsi commented on Nov 1, 2018

    @mqudsi
    Contributor

    There's (currently) no command-line option to skip the user's config.fish (although it might be a good idea), but depending on what you execute you may be able to get away with redefining HOME before launching fish.

    env HOME=/dev/null fish /path/to/fisher_download_script.fish &

    will execute without a user-modified configuration and without any "known" configuration. To instead use a custom fisher environment, you can point HOME to a pre-installed directory containing whatever functions your fisher scripts need in a .config/fish/functions subdirectory of that directory.

    Make sure to restore HOME for any external commands you run within your script, though!

  24. jorgebucaran commented on Nov 1, 2018

    @jorgebucaran
    Author

    Thanks, @mqudsi. I'll definitely try it out.

  25. removed
    bug
    on Nov 15, 2018
  26. jorgebucaran commented on Nov 15, 2018

    @jorgebucaran
    Author

    @mqudsi or @faho Could you summarize the position of the fish-shell developers regarding this issue (for future reference)? Poorly informed users like @tyilo may conclude that what is happening here is a problem in Fisher's end, when in fact it isn't.

  27. faho commented on Nov 16, 2018

    @faho
    Member

    Could you summarize the position of the fish-shell developers regarding this issue (for future reference)?

    My "position" is that currently, you need to guard all commands that "touch the terminal" (that means they produce output or try to fiddle with the terminal settings) with status is-interactive.

    We're open to changes here. A few possibilities:

    • Don't read configuration if not interactive (might be too restrictive?)

    • Add a commandline-option to start fish without configuration (means you need to use it)

    • Don't allow configuration access to the terminal if not interactive (half-baked)

    But until then, not guarding is a user error.

  28. removed this from the fish-future milestone on Dec 16, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions