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.

Opening Atom on MacOS from Desktop results in High CPU usage #22507

Open

Description

@ed9w2in6

Prerequisites

^ Have not done this as it doesn't fit my case. Ran: /Applications/Atom.app/Contents/MacOS/Atom --safe instead of atom --safe, issue persists.

^ Closed: #13317, #13084.

^ Not applicable

Description

Similar issue to the closed issues of #13317 and #13084.
I believe it is the same problem, however, I am not using Linux but MacOS.

Steps to Reproduce

  1. Open Atom from Desktop mode on a Mac. (Click any file that would be opened by Atom, or click the app itself. )
  2. do ps aux | grep zsh and observed the dangling /bin/zsh -ilc command env processes.

Quote from #13084:

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

Actual behavior: WOOOOOOOOSSHHHH goes the laptop fan

Additionally, atom does not respond if clicked on the following buttons: About Atom, View License
to any operation that involves opening a file.

I have not test all buttons so there may be more.

Reproduces how often:

Only if I launch atom from Desktop mode, it works perfectly fine if launched from terminal.
For my use case I rarely does this so I did not notice the issue until now, it could have been there for a while.

Versions

Atom    : 1.57.0
Electron: 9.4.4
Chrome  : 83.0.4103.122
Node    : 12.14.1

MacOS: 11.4(20F71)
SHELL: zsh 5.8 (x86_64-apple-darwin20.0)

Additional Information

Since I rarely launch atom from Desktop, it does not affect me much.
Hence the current workaround is to launch atom from a shell.

As stated in the closed issue of #13084, it is likely due to the shell out process.
The reason that it does not affect Atom started from a shell is because ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT=true is set in atom.sh.
Launching Atom from shell via /Applications/Atom.app/Contents/MacOS/Atom --safe will trigger the same issue, as that is the executable that will be ran if launched in Desktop mode. ( This is how MacOS Applications works. )

Activity

  1. ed9w2in6 commented on May 31, 2021

    @ed9w2in6
    Author

    I found the cause for the bug, in my .zshrc file I did:

    # make zsh appears to load faster.
    precmd
    print -Prn $PROMPT

    I made zsh's interactive command prompt prints stuff on startup to make it appears to load up quicker ( inspired by powerlevel10k ), and that upsets the Atom app in which it doesn't terminate.

    I tried printing to /dev/stderr instead of /dev/stdout but it did not solve the problem without removing the text printing commands in .zshrc.

    I don't think that it is not acceptable to print stuff to stdout in .zshrc, since it is supposed to be sourced for interactive prompt only.

    I think an App or script should be running /bin/zsh -lc command env instead of /bin/zsh -ilc command env, or perhaps allowing one to disable the shelling out behaviour as an option. ( I know about the command line variable of ATOM_DISABLE_SHELLING_OUT_FOR_ENVIRONMENT, but I am not sure I can config it for Desktop mode. )
    Is that not possible to allow such options for the use case of Atom?

  2. ed9w2in6 commented on Jun 5, 2021

    @ed9w2in6
    Author

    I wrote this so I will just quote it.
    from: desktop/desktop#12320 (comment)

    ...

    Interesting. Well I tested my precmd and it seems that this is keeping zsh alive:

    # Took from: https://superuser.com/questions/357107/zsh-right-justify-in-ps1
    prompt-length() {  
       emulate -L zsh
       local -i COLUMNS=${2:-COLUMNS}
       local -i x y=${#1} m #MAX_acc=1000 acc=1  
       if (( y )); then
           while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
               x=y
               (( y *= 2 ))
    #          (( acc += 1 ))
           done
    #      unset acc;
    #      local -i acc=1;
           while (( y > x + 1 )); do
               (( m = x + (y - x) / 2 ))
               (( ${${(%):-$1%$m(l.x.y)}[-1]} = m ))
    #          (( acc += 1 ))
           done
       fi  
       print "$x"
    }

    The function is used to allow one to create a multi-lined left and right aligned PROMPT.
    The logic of cryptic lines like: ${${(%):-$1%$y(l.1.0)}[-1]} is to first do PROMPT expansion ( like colours, etc. ) for $1, then
    see if its length is less then the integer in $y, append '1' to $1, else append '0'. [-1] extract the trailing 0 or 1.
    The rest should be fairly readable.

    The code is basically a binary search to determine the length of the interpolated string.

    I had tried to make sure the loop terminates by setting a maximum amount of iteration, but they do nothing so I commented them out / removed them. The loop should always terminate regardless, which it does, as a matter of fact I am using it daily with no issues. For some reason the behaviour is different when the shell is spawned by child_process.

    I am puzzled with this.

    At the moment, bypassing this function on startup seems to have stopped the issue from happening.

  3. ThatXliner commented on Jun 5, 2021

    @ThatXliner
    Contributor

    Doesn't seem Atom-specific...

  4. sami-eljabali commented on Dec 19, 2021

    @sami-eljabali

    I've been experiencing the same. It has been hogging CPU with the app shut:

    Screen Shot 2021-12-18 at 23 56 37

    Mac: 11.6
    Atom: 1.58.0

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions