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

Bug: BLE hangs when using git grep in large repo #246

Open
DhruvaG2000 opened this issue Oct 28, 2022 · 24 comments
Open

Bug: BLE hangs when using git grep in large repo #246

DhruvaG2000 opened this issue Oct 28, 2022 · 24 comments

Comments

@DhruvaG2000
Copy link

ble version:

echo $BLE_VERSION
0.4.0-devel3+1c7f7a1

Bash version:

echo "$BASH_VERSION ($MACHTYPE)"
5.0.17(1)-release (x86_64-pc-linux-gnu)

I use git grep alot, and whenever I go on to type git grep "... it just freezes for a solid 15-20 seconds doing I don't know what. I think this maybe an awk script related issue in ble but I am not sure. One can probably best reproduce this after cloning the linux kernel and try to git grep something.

@akinomyoga
Copy link
Owner

akinomyoga commented Oct 28, 2022

Thank you for the report. It doesn't seem to reproduce in my environment. I tried typing git grep '' ... in a git repository of Linux, but it doesn't freeze. I'm on the following commit:

commit 23758867219c8d84c8363316e6dd2f9fd7ae3049 (HEAD -> master, origin/master, origin/HEAD)
Merge: 7dd257d02eb3 84ce1ca3fe9e
Author: Linus Torvalds <[email protected]>
Date:   Thu Oct 27 13:36:59 2022 -0700

Maybe it is related to the programmable completion loaded in your environment. Could you provide the following information?

  • Q1: What is the output of pressing C-x C-b (press Ctrl-X and then Ctrl-V)?
  • Q2: What is the result of the following commands after recovering from the freeze?
$ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git # <-- This is the result in my environment
$ (shopt -s extdebug; declare -F __git_wrap__git_main) # <-- replace "__git_wrap__git_main" with the name found above
__git_wrap__git_main 3557 /usr/share/bash-completion/completions/git # <-- This is the result in my environment
  • Q3: While ble.sh is freezing, what is the result of the following command in another terminal? (Instead of pasting all the output, you can extract the related tree if you want.)
$ ps uf
  • Q4: When auto-complete is turned off by the following command, does the situation change?
$ bleopt complete_auto_complete=

@DhruvaG2000
Copy link
Author

What is the output of pressing C-x C-b (press Ctrl-X and then Ctrl-V)?

➜ bleopt complete_auto_complete=

Q2: What is the result of the following commands after recovering from the freeze?

➜ complete -p git
complete -o bashdefault -o default -o nospace -F __git_wrap__git_main git
➜ (shopt -s extdebug; declare -F __git_wrap__git_main)
__git_wrap__git_main 3247 /usr/share/bash-completion/completions/git

output of ps uf :

 13:08:13 linux on  master ➜  ps uf
USER         PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
dhruva    534172  0.0  0.0   9732  3124 pts/12   Ss+  10:57   0:00 tmux -u
dhruva    542189  0.0  0.0  34168 28624 pts/18   Ss   13:07   0:01 -bash
dhruva    546251  0.0  0.0  11492  3312 pts/18   R+   15:20   0:00  \_ ps uf
dhruva    534182  0.8  4.8 1601456 1595740 pts/15 Ss  10:57   2:06 -bash
dhruva    546229  106  6.3 2086348 2076284 pts/15 R+  15:20   0:05  \_ /usr/bin/nawk -v AWKTYPE=nawk -F ?        BEGIN { mandb_count = 0; }       mode == "mandb" 
dhruva    531645  0.0  0.0  35376 29800 pts/13   Ss+  10:55   0:04 -bash
dhruva    402779  0.0  0.0  34168 28464 pts/11   Ss   Oct25   0:00 -bash

and the below does help, as in the lag goes away.
bleopt complete_auto_complete=

@akinomyoga
Copy link
Owner

What is the output of pressing C-x C-b (press Ctrl-X and then Ctrl-V)?

➜ bleopt complete_auto_complete=

Ah, sorry. It was a typo of C-x C-v.

  • Q1': I'm sorry, but could you try C-x C-v?
dhruva    534182  0.8  4.8 1601456 1595740 pts/15 Ss  10:57   2:06 -bash
dhruva    546229  106  6.3 2086348 2076284 pts/15 R+  15:20   0:05  \_ /usr/bin/nawk -v AWKTYPE=nawk -F ?        BEGIN { mandb_count = 0; }       mode == "mandb" 

This information is helpful, but I still don't have an idea why this could take such a long time. I notice that both Bash and nawk have extremely large memory uses of 1.6..2.0 GB. This means that git completion probably produces an extremely large number of candidates or a candidate with an extremely long candidate.

  • Q5: What is the result of the following command?
$ ble/complete/mandb/generate-cache git; ls -l "$ret"
  • Q6: Your ble.sh version 0.4.0-devel3+1c7f7a1 seems to be the one from four months ago. Could you update ble.sh by running ble-update and see if the situation changes?

@DhruvaG2000
Copy link
Author

DhruvaG2000 commented Oct 28, 2022

Q1:

I'm sorry, but could you try C-x C-v?

This just pastes my clipboard, nothing useful here I believe.
I am ssh-ing into my machine from VS code maybe that's why the key bindings are funny.

Q5:

➜ ble/complete/mandb/generate-cache git; ls -l "$ret"
.rw-rw-r-- 2.0k dhruva 28 Oct 16:11 /home/dhruva/.ble.sh/out/cache.d/1000/complete.mandb/en_US.UTF-8/git

Q6:
Updating to latest doesn't seem to have helped:

➜ echo $BLE_VERSION
0.4.0-devel3+a144ffa807b4

What's annoying is C-c or C-z doesn't seem to kill whatever is causing the hang!

--edit--
after a while of C-c I get the following:

➜ -bash: fg: current: no such job
-bash: fg: current: no such job
[ble: exit 1]
-bash: fg: current: no such job

@akinomyoga
Copy link
Owner

akinomyoga commented Oct 28, 2022

Thank you.

I'm sorry, but could you try C-x C-v?

This just pastes my clipboard, nothing useful here I believe. I am ssh-ing into my machine from VS code maybe that's why the key bindings are funny.

OK, it is because you are using the VS Code terminal, in which C-v cannot be used.

  • Q1'': Can you rebind another key sequence (for example, C-t) to the corresponding widget by the following command and press the key sequence?
$ ble-bind -f C-t display-shell-version
$ <-- here, press "C-t"

Updating to latest doesn't seem to have helped:

➜ echo $BLE_VERSION
0.4.0-devel3+a144ffa807b4
  • Q7: Hmm, what is your git version?
$ git --version

What's annoying is C-c or C-z doesn't seem to kill whatever is causing the hang!

This is somewhat intentional. ble.sh disables signals, SIGINT (C-c), SIGTSTP (C-z), etc., except when the user commands are running.

  • One reason is that it is hard to properly and robustly handle signals when ble.sh is running. There is really no clean way to solve it.
    • a. If we just naively enable signals, C-c will also kill the entire processing of ble.sh which is not expected.
    • b. It is in principle possible to handle SIGINT by trapping it and emulate its behavior by using the DEBUG trap, but it's not robust enough and can conflict with the user's DEBUG trap.
    • c. Another possibility is to only enable SIGINT while the programmable completion is running, but it still requires the emulation by the DEBUG trap, and also it requires calling the external commands stty every time the programmable completion is invoked. The programmable completion may be called several times for a single keystroke so the external command stty can be called from a few to about ten times for each key in principle, which might cause another delay of a few seconds for each key in slow systems such as Cygwin and MinGW.
  • Another reason is that requiring users to manually kill the hanging completions by themselves seems to be the wrong solution. To begin with, a properly designed programmable completion should not block for a long time. This is the problem of the programmable completion and doesn't seem to be what the lower layer (ble.sh) needs to take care of ideally. That being said, there are always badly designed completions in wild, so I admit that ble.sh wanted to work around them if there were a clean way to do it. The problem is that I haven't yet found such a way because of the previous point.

@akinomyoga
Copy link
Owner

Anyway, if we can identify the cause for this specific case, I think I can add a workaround for this specific case. This is the reason I try to collect the information.

@DhruvaG2000
Copy link
Author

Q1:

➜ 
GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu) [Linux Mint 20.3]
ble.sh, version 0.4.0-devel3+a144ffa807b4 (noarch)
bash-completion, version 2.10 (hash:b6da7f7edfc1c3c5196c86c81fb05fce96f83c03, 74550 bytes) (noarch)
starship, version 1.9.1 (rustc 1.62.0 (a8314ef7d 2022-06-27),stable-x86_64-unknown-linux-gnu 2022-07-19 10:03:48 +05:30)
locale: LANG=en_US.UTF-8
terminal: TERM=screen-256color wcwidth=12.1-west/15.0-2+ri, tmux:0 (84;0;0), unknown:- (0;276;0)

git version:

git --version
git version 2.25.1

If it is too much of a hassle I might just have to add a bleopt complete_auto_complete= to my bashrc or somehow disable git autocomplete . I am content with autocompletion of path names and file names and history based auto complete.

@akinomyoga
Copy link
Owner

GNU bash, version 5.0.17(1)-release (x86_64-pc-linux-gnu) [Linux Mint 20.3]
ble.sh, version 0.4.0-devel3+a144ffa807b4 (noarch)
bash-completion, version 2.10 (hash:b6da7f7edfc1c3c5196c86c81fb05fce96f83c03, 74550 bytes) (noarch)
starship, version 1.9.1 (rustc 1.62.0 (a8314ef7d 2022-06-27),stable-x86_64-unknown-linux-gnu 2022-07-19 10:03:48 +05:30)
locale: LANG=en_US.UTF-8
terminal: TERM=screen-256color wcwidth=12.1-west/15.0-2+ri, tmux:0 (84;0;0), unknown:- (0;276;0)
git --version
git version 2.25.1

Thank you for this information. I'll later try setting up the same environment and see if the problem reproduces there. If I cannot reproduce the problem, I'll ask more questions then.

If it is too much of a hassle I might just have to add a bleopt complete_auto_complete= to my bashrc or somehow disable git autocomplete . I am content with autocompletion of path names and file names and history based auto complete.

For the time being, if you are fine with turning off the custom git completion, you can put the following line somewhere in bashrc or blerc:

complete -F _minimal git

akinomyoga added a commit that referenced this issue Oct 29, 2022
@akinomyoga
Copy link
Owner

akinomyoga commented Oct 29, 2022

I have set up a new instance of Linux Mint 20, installed git and starship, and tried ble.sh in the Linux repository, but the problem doesn't seem to happen still.

Q8: I thought the problem happens in your environment by just typing git grep '' ..., but maybe I misunderstand the situation where the problem happens. Could you check if the procedure in the following clip is correct?

Mint20-screen0.webm

Q9: I am now thinking about the possibility that the problem is caused by some specific aspect of your repository. The Linux repository is a typical large repository, but have you actually tried the Linux repository and confirmed that the problem also arises in the Linux repository? If not, could you also check if the problem arises in the Linux repository?

Q10: I have created a special branch gh246 (fcd090d) to collect information on the situation. Could you check out the branch gh246 and see if the problem happens [see the following commands]? If the problem arises, could you attach the log file created at ~/blesh-gh246-debug.log in the reply comment? You may also attach another file blesh-gh246-compgen.txt if its size is not so large, but do not attach it if the size is large.

$ cd <your-ble.sh-repository>
$ git fetch origin
$ git checkout -b gh246 origin/gh246
$ make
$ make install .... # <-- if neccesary
$ bash # <-- start a new session with gh246
$ cd <your-git-repository>
$ git grep '' .... # <-- test if the problem arises
$ ls -la ~/blesh-gh246-{debug.log,compgen.txt} # <-- check if the log files are created

What I would like to request is the content of the file blesh-gh246-debug.log. After finishing the test, you may recover the original master branch and clean up the log files.

$ exit # <-- end the "gh246" session
$ cd <your-ble.sh-repository>
$ git checkout master
$ make
$ make install .... # <-- if necessary
$ rm -f ~/blesh-gh246-{debug.log,compgen.txt}

Q11: Also, it might be possible that other custom configurations in your bashrc/blerc would be causing the problem. Could you check if the problem still happens with just plain ble.sh plus bash-completion?

$ cp ~/.bash_history ~/.bash_history.bk           # <- Please back up your history file. If you set HISTFILE,
                                                  #    back up "$HISTFILE" instead of ~/.bash_history
$ PS1='$ ' bash --norc                            # <- This starts a Bash session without your .bashrc
$ source /usr/share/bash-completion/bash_completion # <- Load bash-completion
$ source /path/to/ble.sh --norc                   # <- Load ble.sh (replace "/path/to" with the location of your "ble.sh" file)
$                                                 # <- Is the problem reproduced hereafter?

After the testing session is closed, you may optionally recover the original history file:

$ cp ~/.bash_history.bk ~/.bash_history

@DhruvaG2000
Copy link
Author

Q8: I thought the problem happens in your environment by just typing git grep '' ..., but maybe I misunderstand the situation where the problem happens. Could you check if the procedure in the following clip is correct?

I see in the clip that you're not really using git grep as desired, try git grep "Linus" or seomthing and when I just start tying Li then it freezes there before closing the quotes. Something tried to autocomplete within the quotes and gets hung up.

I am now thinking about the possibility that the problem is caused by some specific aspect of your repository.

I doubt it, mine is a clean clone of upstream linux stable:

❯ git remote -vv
origin  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git (fetch)
origin  https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git (push)

And again, I observe this is other large repos like zephyr-RTOS or u-boot as well.

: I have created a special branch gh246 (fcd090d) to collect information on

Will get back to you on this. Thanks for your kind support so far.

@DhruvaG2000
Copy link
Author

DhruvaG2000 commented Oct 29, 2022

Q10. Did as you suggested and am attaching the debug.log file. The other compgen file is 100+ MB So is too large.

comp_func: __git_wrap__git_main
----------------------------------------
size: 126650229
.�[1;33mr�[31mw�[0m�[38;5;244m-�[33mr�[31mw�[38;5;244m-�[33mr�[38;5;244m--�[0m �[1;32m2.0�[0m�[32mk�[0m �[1;33mdhruva�[0m �[34m29 Oct 11:25�[0m �[36m/home/dhruva/.ble.sh/out/cache.d/1000/complete.mandb/en_US.UTF-8/�[0mgit
[head /home/dhruva/blesh-gh246-compgen.txt]
_
__
$$divI
$$divI_10
$$divI_12
$$divI_14
$$divI_15
$$divI_3
$$divI_5
$$divI_6
[tail /home/dhruva/blesh-gh246-compgen.txt]
zyxel_omninet_device
ZYXEL_OMNINET_ID
ZYXEL_VENDOR_ID
ZYXW
zz
z_zero
zzz
ZZZ_genl_family
ZZZ_genl_mcgrps
ZZZ_genl_ops
start: 1667022915.527157
end:   1667022922.780590
----------------------------------------

@DhruvaG2000
Copy link
Author

Hmm..

Q11: Also, it might be possible that other custom configurations in your bashrc/blerc would be causing the problem

This might be, because after following as you said plain ble.sh plus bash-completion git grep isn't freezing anymore in the same repo. Wonder if it is tmux or starship of bashrc that is the issue though.

@akinomyoga
Copy link
Owner

akinomyoga commented Oct 29, 2022

I see in the clip that you're not really using git grep as desired, try git grep "Linus" or seomthing and when I just start tying Li then it freezes there before closing the quotes. Something tried to autocomplete within the quotes and gets hung up.

I tried inputting git grep "Linus" several times, but still, it doesn't freeze in my environment.

Q10. Did as you suggested and am attaching the debug.log file. The other compgen file is 100+ MB So is too large.

OK, thank you for the information. Then, we could confirm that somehow the completion produces an unreasonable amount of completions. I'm not sure why it generates such a large amount of completions in your environment. In my environment, the compgen result for git grep '' ... is just a list of tags, branches, and other git refs, and the size is not that large. No completions are generated for git grep "Li....

Q11: Also, it might be possible that other custom configurations in your bashrc/blerc would be causing the problem

This might be, because after following as you said plain ble.sh plus bash-completion git grep isn't freezing anymore in the same repo. Wonder if it is tmux or starship of bashrc that is the issue though.

I tried the same inside tmux, but it still doesn't reproduce. As the problem isn't reproducible in my environment, the only way to identify the problem is to test it in your environment. Sorry but

  • Q12: Could you identify the affecting lines in your bashrc/blerc (e.g. by trying several times with turning off different lines of bashrc/blerc)?

@akinomyoga
Copy link
Owner

akinomyoga commented Oct 29, 2022

Q10. Did as you suggested and am attaching the debug.log file. The other compgen file is 100+ MB So is too large.

Hmm, I'm interested in the full content of the file. Maybe it contains some hints.

  • Q13: If it doesn't hit GitHub's filesize limit, could you compress the file in a zip file and attach it in a reply? The filesize limitation seems to be 25 MB for zip files (after compression).

@akinomyoga
Copy link
Owner

akinomyoga commented Oct 29, 2022

I'm now checking the implementation of the git completion. As far as I see, the git completion seems to just generate the list of git refs. If that is correct, maybe __git_refs generates the large output.

  • Q14: After the freezing, what is the result of the following command in the affected repository (such as in the Linux repository)?
$ __git_refs '' '' '' '' ' ' | wc

@akinomyoga
Copy link
Owner

@DhruvaG2000 Any updates?

@DhruvaG2000
Copy link
Author

The time period of the freezes has gone down a bit for some reason... but it's still there. I have been away from work for some time. Will post the answers to above qns when I get back.

@akinomyoga
Copy link
Owner

Thanks! I'll wait for you.

@DhruvaG2000
Copy link
Author

➜ __git_refs '' '' '' '' ' ' | wc
    462     462    7401

@akinomyoga
Copy link
Owner

@DhruvaG2000 Sorry for the delay, and thank you for the result of Q14. This means that what generates the large output of 100+ megabytes is not the implementation of __git_refs, but something other causes the problem. I think I actually need the result of Q12 and Q13 so was waiting for the results of them for a while, but then I forgot to reply.

@DhruvaG2000
Copy link
Author

Q12: Could you identify the affecting lines in your bashrc/blerc (e.g. by trying several times with turning off different lines of bashrc/blerc)?

I dont have anything but aliases, and few exports. I really need all of them so I don't really think that's relevant.

One point I thought is maybe starship was causing the issue, however disabling it doesn't still seem to help

@akinomyoga
Copy link
Owner

Q12: Could you identify the affecting lines in your bashrc/blerc (e.g. by trying several times with turning off different lines of bashrc/blerc)?

I dont have anything but aliases, and few exports. I really need all of them so I don't really think that's relevant.

Thank you for your reply! I am confused because I thought in the answer to Q11 you have told that the plain ble.sh and bash-completion doesn't have the problem, but in this reply to Q12 you seem to be claiming that the difference of these two set of settings (where one has the problem and the other doesn't) is not relevant. Am I missing something? What did the "plain ble.sh plus bash-completion git grep" mean?

Also, I'm not sure what kind of aliases and exports you have, but in general some names of aliases can possibly interfere with the internal processing of shell codes, and also exported variables can change the behavior of commands. Based on the currently available information to me, I cannot really conclude your aliases and exports are not related to the present problem. Could you prove it by actually disabling the aliases and exports and see what happens?

I really need all of them

Note that I'm not requesting to disable your aliases and exports in your daily sessions, but I just want to get more information on what is going on. So you can just make your aliases and exports back after you see the result of Q12. I will provide the proper fix once we could identify the cause.

@akinomyoga
Copy link
Owner

Ah, I noticed the log file you sent me now! Thank you, and sorry that I missed it! I'll later check it!

@akinomyoga
Copy link
Owner

PFA.
blesh-gh246-debug.log

Sorry, but what I'd like to see is the content of blesh-gh246-compgen.txt. If the filesize is the problem or you don't want to expose the content in public, you can zip the file and directly send it to my email address [email protected].

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants