Skip to content
This repository was archived by the owner on Mar 3, 2023. It is now read-only.
This repository was archived by the owner on Mar 3, 2023. It is now read-only.

Shelling out to collect environment variables is creating runaway 100% CPU processes on Linux #13084

Closed

Description

@fooishbar

Prerequisites

Description

I'm fairly sure this will end up being an Electron issue, but here goes ...

When I start atom-beta (1.12.0b4, though was present with b3 at least), it spawns a shell ('env') subprocess which burns 100% CPU, attempting to read stdin forever:

systemd,1,1 --system --deserialize 126
  ├─atom,15392,10213
  │   ├─atom,15403,10213
  │   │   └─atom,15466,10213
  │   │       ├─zsh,15497,10213 -ilc command env

strace on the shell shows this looping forever:

rt_sigprocmask(SIG_SETMASK, [], [TSTP TTIN TTOU], 8) = 0
read(0, NULL, 0)                        = 0
rt_sigprocmask(SIG_BLOCK, [TSTP TTIN TTOU], [], 8) = 0
getpgrp()                               = 10213
ioctl(15, TIOCGPGRP, [11445])           = 0
getpgrp()                               = 10213
ioctl(15, TIOCGPGRP, [11445])           = 0
rt_sigprocmask(SIG_SETMASK, [], [TSTP TTIN TTOU], 8) = 0
read(0, NULL, 0)                        = 0
rt_sigprocmask(SIG_BLOCK, [TSTP TTIN TTOU], [], 8) = 0

Sometimes this process blocks Atom startup, and you have to kill the shell for Atom's window to show. Sometimes Atom works just fine despite this, and you only realise later when you wonder why your system is slow, and kill the extraneous process. Sometimes closing Atom takes the rogue shell process with it, and sometimes it outlives Atom. Sometimes everything works fine and I can't reproduce it at all.

Either way, safe mode or not has no effect on it, and nothing bright turns up with --enable-logging. Timecop shows 'window load time' taking an ungodly amount of time, but with no insight into why.

Happy to supply more details or attempt debugging as needed, with the caveat that I have no idea what I'm doing in JavaScript.

Steps to Reproduce

  1. Have my system
  2. Run Atom beta

Expected behavior: 'What a nice normal text-editing experience this is'

Actual behavior: WOOOOOOOOSSHHHH goes the laptop fan

Versions

Atom 1.12.0b4 (also occurred with b3)
Fedora 25 (kernel 4.8-rc8+, glibc 2.24, etc)

Activity

  1. thomasjo commented on Oct 27, 2016

    @thomasjo
    Contributor

    This originates in our process environment patching. I'm guessing something is preventing zsh from exiting.

    Would you mind running the follow in a terminal, and reporting back what the output is?

    $ zsh -ilc command env
    
  2. added
    linux
    on Oct 27, 2016
  3. fooishbar commented on Oct 27, 2016

    @fooishbar
    Author

    Oddly enough, just a screen-clear character, then exits immediately:

    % zsh -ilc command env >foo 2>&1
    % xxd foo
    00000000: 1b5b 334a 1b5b 481b 5b32 4a              .[3J.[H.[2J
    

    Thanks for the prompt response!

  4. fooishbar commented on Oct 27, 2016

    @fooishbar
    Author

    Ah, following the quoting for "command env" rather than as separate arguments, it dumps my entire environment and then exits immediately. I can share a redacted version with you, if the actual content is of interest, but it does simply print and exit.

  5. drewmnoel commented on Oct 30, 2016

    @drewmnoel
    Contributor

    I have this problem as well. Confirmed on zsh 5.2 as well as GNU bash 4.3.46(1)

    Versions:

    $ atom --version
    Atom    : 1.13.0-dev-630f146
    Electron: 1.3.6
    Chrome  : 52.0.2743.82
    Node    : 6.3.0
    
    $ apm --version
    apm  1.14.0
    npm  3.10.5
    node 4.4.5
    python 3.5.2
    git 2.10.1
    

    Attempted to make a minimal working example, but the extracted function actually works just fine for me on node v6.9.1

    https://gist.github.com/drewmnoel/7da14895c20b0fa8b376c18354318caf

    Edit: Of particular interest is that it works as expected in foreground mode. Watching ps confirms that it requests information from the shell and continues just fine. @fooishbar is this problem absent in foreground mode (atom -f)?

  6. TheDaemoness commented on Nov 10, 2016

    @TheDaemoness

    I appear to have this issue as well.

    When I launch atom-beta from a terminal instance, it runs without issues, regardless of whether it's launched in foreground mode or not, and whether I run the shell script in /usr/bin or the actual binary in /usr/share/atom-beta.

    When I launch it through a provided desktop file, then the issue described in the bug report manifests. Running the exact same command used in the desktop file (minus the %F of course) does not reproduce this issue, and editing the desktop file to launch Atom using a simple /usr/bin/atom-beta does not fix it. Atom is the only application I have that causes this issue, including other Electron-based programs.

    % atom-beta --version
    Atom    : 1.12.0-beta3
    Electron: 1.3.6
    Chrome  : 52.0.2743.82
    Node    : 6.3.0
    
    % zsh --version
    zsh 5.2 (x86_64-unknown-linux-gnu)
    
    % cat /usr/share/applications/atom-beta.desktop
    [Desktop Entry]
    Name=Atom Beta
    Comment=A hackable text editor for the 21st Century.
    GenericName=Text Editor
    Exec=env PYTHON=python2 XMODIFIERS= /usr/share/atom-beta/atom %F
    Icon=atom-beta
    Type=Application
    StartupNotify=true
    StartupWMClass=Atom
    Categories=GNOME;GTK;Utility;TextEditor;Development;
    MimeType=text/plain;
    
  7. winstliu commented on Nov 10, 2016

    @winstliu
    Contributor
  8. bsandu commented on Nov 10, 2016

    @bsandu

    Same issue here: "/bin/bash -ilc command env" keeps CPU in full load, and atom never starts. Only killing this will successfully load atom.
    Run on ubuntu 16.04
    Atom version 1.12.0+1-1webupd80

  9. dweldon commented on Nov 10, 2016

    @dweldon

    I'm experiencing the same symptoms with atom 1.12.0 and bash 4.3.42 under linux mint. If I kill the terminal, atom seems to start up fine.

  10. XzAeRo commented on Nov 10, 2016

    @XzAeRo

    I'm experiencing the same.

    I invoke $ atom project/folder/, but Atom only starts once I kill the /bin/zsh -ilc command env process. Otherwise Atom doesn't start and said process burns the CPU at 100% in all the cores.
    Once the command is killed, Atom starts normally. For example:

    $ atom project/folder/
    # atom doesn't open
    $ kill 12341
    # burning process is killed and Atom opens its window
    

    This is my installation, thorugh the webupd8 channel.

    $ lsb_release -a
    No LSB modules are available.
    Distributor ID: Ubuntu
    Description:    Ubuntu 16.04.1 LTS
    Release:    16.04
    Codename:   xenial
    
    $ zsh --version
    zsh --version
    zsh 5.1.1 (x86_64-ubuntu-linux-gnu)
    
    $ atom --version
    Atom: 1.12.0
    Electron: 1.3.6
    Chrome: 52.0.2743.82
    Node: 6.3.0
    
    $ apm --version
    apm  1.12.9
    npm  3.10.5
    node 4.4.5
    python 2.7.12
    git 2.7.4
    
  11. joefitzgerald commented on Nov 10, 2016

    @joefitzgerald
    Contributor

    For anyone reporting they are experiencing this issue, please run the relevant command and paste the output:

    • /bin/bash -ilc "command env"
    • /bin/zsh -ilc "command env"
    • <path-to-your-shell-here> -ilc "command env"

    You can find out what shell is being used by determining what the SHELL env variable is set to.

    Additionally, please post the output from which -a env; e.g.:

    $ which -a env
    /usr/bin/env
    

    It sounds like we should at a minimum establish a timeout for the invocation of this command so that it will be killed if it takes too long.

  12. TheDaemoness commented on Nov 11, 2016

    @TheDaemoness

    The "command env" commands (for both /bin/bash and /bin/zsh) both print a long list of environment variables without significant delay and exit normally. If there are any particular environment variables you wish to know the contents of, please let me know.

    % which -a env
    /usr/bin/env
    
    % echo $SHELL
    /bin/zsh
    
    % getent passwd $LOGNAME | cut -d: -f7
    /bin/zsh
    
  13. 69 remaining items

  14. forivall commented on Nov 19, 2016

    @forivall

    Minimal reproduction case: https://gist.github.com/forivall/99bd9b913ab774ced025be2483a59879
    Usage: python xdg-launch.py ./spawn-ilc.desktop. You'll need to modify the path in the .desktop file

    Now to figure out if this is a gnome or node issue. Changing it from zsh to bash causes the same issue.

    Removing the -i (interactive) option (so that it's just '-lc') stops it from hanging, though it may not be correct.

  15. forivall commented on Nov 19, 2016

    @forivall

    @joefitzgerald the aur package atom-editor-bin downloads the official distribution, makes minimal tweaks for arch, and then installs it globally, just as if it were installed on ubuntu or fedora.

    If someone else has the time to try out my reproduction case on ubuntu, that would be great.

    the following gist makes it work, by using a pty for stdin:
    https://gist.github.com/forivall/825f4a94eaf30b96dec522d40bb47887

  16. joefitzgerald commented on Nov 19, 2016

    @joefitzgerald
    Contributor

    @forivall I appreciate your effort in trying to identify root cause. It does seem like something very specific to arch linux at this point, and it seems like you are on the right track to look at the method of invocation for non-terminal launched atom on arch.

    Very interested to hear the outcome of your investigation!

  17. forivall commented on Nov 19, 2016

    @forivall

    I started up an ubuntu 16.10 vm: with the minimal reproduction, the same issue occurs, and the same fix works. 🎉

    Edit: also, by launching atom with the xdg-launch.py script (python xdg-launch.py /usr/share/applications/atom.desktop), the CPU will be pegged at 100% by a runaway bash process. (I installed lxde on the vm, and launching from its menu doesn't trigger the issue. But lxde uses qt)

    This may be a different issue. Do y'all think I should open a new bug for it, or keep working in here?

  18. GabMus commented on Nov 21, 2016

    @GabMus

    Hello, I'm having the same issue with the zsh process taking 100% of the CPU. I tested it in Arch Linux, using the official community repo package, downloading the tar.gz from atom release page for the stable and the beta versions.

    All of these versions share the same problem, and weirdly enough it only happens when launching atom from a .desktop file (via gnome shell in my case) and doesn't when I launch atom from the command line.

    After reading @arcticicestudio comment in #13279 I came up with a sort of workaround, I simply made a .desktop file with the following line: Exec=sh -c "ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=true atom" and it seems to work fine.

    I hope this can be of help to find a long term solution to this problem, which is getting really annoying and prevents many people from using such a great editor as atom.

  19. added a commit that references this issue on Nov 21, 2016
  20. nathansobo commented on Nov 21, 2016

    @nathansobo
    Contributor

    @joefitzgerald should we reopen this issue? Seems like we're still getting reports but it's really hard to tell what's real with all these different custom packaging solutions.

  21. thomasjo commented on Nov 21, 2016

    @thomasjo
    Contributor

    @nathansobo We should at least attempt to reproduce the reported problems using only official distributions of Atom.

    This means we'll need to check Arch Linux at least, possibly with both GNOME and KDE. On the Ubuntu side of things, it might be enough to check Ubuntu GNOME 16.04. The only reported problems I've seen on Ubuntu 16.04 is in relation to webupd8.

  22. phw commented on Nov 23, 2016

    @phw

    I debugged this a bit and can reproduce it with the following test script (extracted from src/update-process-env.js):

    const childProcess = require('child_process')
    const cmd = 'command env'
    const shell = process.env.SHELL  // zsh or bash doesn't matter, behavior is the same
    // const shell = '/bin/bash'
    
    const child = childProcess.spawn(shell, ['-ilc', cmd], {
       encoding: 'utf8',
      //  detached: true,
      stdio: ['ignore', 'pipe', process.stderr]
    })
    child.on('error', (e) => {
      console.log('error', e)
    })
    child.stdout.on('data', (data) => {
      console.log(data.toString('utf8'))
    })
    child.on('close', (code, signal) => {
      console.log('close', code, signal)
    })

    Launching this directly from a shell works, even if I set an empty environment like so:

    env -i SHELL=/bin/bash node spawn.js
    

    Launching the same from a desktop file in Gnome 3.22 leads to the shell task endlessly consuming 100% of CPU. I used the following desktop file:

    [Desktop Entry]
    Name=Spawn Node Test
    Exec=env SHELL=/bin/bash node /home/phw/devel/spawn.js
    Icon=atom
    Type=Application
    

    Two things help to solve this issue:

    a) Enable detached: true when spawning the child process
    b) Remove the -i flag from the shell call

    I think b) would actually be correct anyway, since this is in no way an interactive shell.

    EDIT: Just to be clear: I still don't know exactly why this is happening, I just know the issue can be circumvented removing the -i flag.

  23. joefitzgerald commented on Nov 23, 2016

    @joefitzgerald
    Contributor

    @maxbrunsfeld guess we want to add detached back in.

    @phw thank you for the detailed analysis. We do actually want the -i flag as the intent of this behavior is to ensure the shell initializatoon scripts that get run for an interactive shell are run. This ensures that atom has the same environment that it would have when invoked from a terminal.

  24. phw commented on Nov 23, 2016

    @phw

    Can this issue be reopened then until a fix is merged? I think this was accidentally closed by #13283

  25. joefitzgerald commented on Nov 23, 2016

    @joefitzgerald
    Contributor

    No, it wasn't closed by that. We should open a new issue with your findings @phw. I will commit to getting this in today.

  26. lock commented on Apr 4, 2018

    @lock

    This issue has been automatically locked since there has not been any recent activity after it was closed. If you can still reproduce this issue in Safe Mode then please open a new issue and fill out the entire issue template to ensure that we have enough information to address your issue. Thanks!

  27. locked and limited conversation to collaborators on Apr 4, 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

    buglinuxmore-information-needed

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions