marlonrichert / zsh-autocomplete

🤖 Real-time type-ahead completion for Zsh. Asynchronous find-as-you-type autocompletion.
MIT License
5.03k stars 144 forks source link

Freezes with 100% CPU when pressing enter on completion #611

Closed pesterhazy closed 12 months ago

pesterhazy commented 1 year ago

zsh-autocomplete (latest master) often freezes with 100% CPU when pressing Enter on a completion

Environment

% typeset -p1 VENDOR OSTYPE ZSH_PATCHLEVEL _autocomplete__funcfiletrace
typeset VENDOR=apple
typeset OSTYPE=darwin22.0
typeset ZSH_PATCHLEVEL=zsh-5.9-0-g73d3173
typeset -a _autocomplete__funcfiletrace=(
  /Users/user/arena/vendor/zsh-autocomplete/zsh-autocomplete.plugin.zsh:4
  /Users/user/.zshrc:23
  zsh:0
)
% git -C ~autocomplete log --oneline -n1
de14622 (HEAD -> master) WIP

Steps to reproduce

Not sure how to repro this in a temp dir. This doesn't always happen but when it does, I try to pick a selection and the terminal freezes with 100% CPU.

I've set the following settings

bindkey '\t' menu-select "$terminfo[kcbt]" menu-select
bindkey -M menuselect '\t' menu-complete "$terminfo[kcbt]" reverse-menu-complete
bindkey -M menuselect '\r' .accept-line

bindkey "^xm" _most_recent_file
pesterhazy commented 1 year ago

Is there a way to get a stacktrace when it freezes to know where in the code the infinite loop is happening?

marlonrichert commented 12 months ago

You could try running set -x before reproducing the problem. In any case, I'm not able to reproduce this. If you can provide more debug info, I'll reopen the issue.

garthk commented 11 months ago

I think I've been hitting this on my work machine. I'll check CPU while hung next week.

garthk commented 11 months ago

Wedged zsh again; confirmed 100% CPU usage. If I'm reading it right, it's spending all its time in zsh' runhookdef calling into complist.so.

profile taken of zsh ```plain Analysis of sampling zsh (pid 46068) every 1 millisecond Process: zsh [46068] Path: /bin/zsh Load Address: 0x10e5d2000 Identifier: zsh Version: 97 Code Type: X86-64 Platform: macOS Parent Process: Code Helper [13423] Date/Time: 2023-07-25 13:18:29.209 +1000 Launch Time: 2023-07-24 10:16:24.467 +1000 OS Version: macOS 13.4 (22F66) Report Version: 7 Analysis Tool: /usr/bin/sample Physical footprint: 5676K Physical footprint (peak): 7564K Idle exit: untracked ---- Call graph: 2399 Thread_6699442 DispatchQueue_1: com.apple.main-thread (serial) 2399 start (in dyld) + 1903 [0x7ff8008cd41f] 2399 zsh_main (in zsh) + 1222 [0x10e602305] 2399 loop (in zsh) + 263 [0x10e5ff35b] 2399 parse_event (in zsh) + 53 [0x10e61f2a7] 2399 zshlex (in zsh) + 141 [0x10e608467] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x27fec [0x10e5f9fec] 2399 ingetc (in zsh) + 316 [0x10e602b60] 2399 zleentry (in zsh) + 384 [0x10e601dc4] 2399 zleread (in zle.so) + 1160 [0x10e7fdecd] 2399 zlecore (in zle.so) + 331 [0x10e7fd8b5] 2399 execzlefunc (in zle.so) + 993 [0x10e7fd47e] 2399 doshfunc (in zsh) + 1329 [0x10e5e929d] 2399 runshfunc (in zsh) + 103 [0x10e5e96ed] 2399 wrap_private (in private.so) + 105 [0x10e87ad78] 2399 runshfunc (in zsh) + 170 [0x10e5e9730] 2399 execode (in zsh) + 207 [0x10e5e53ec] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1bcce [0x10e5edcce] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18707 [0x10e5ea707] 2399 doshfunc (in zsh) + 1329 [0x10e5e929d] 2399 runshfunc (in zsh) + 103 [0x10e5e96ed] 2399 wrap_private (in private.so) + 105 [0x10e87ad78] 2399 runshfunc (in zsh) + 170 [0x10e5e9730] 2399 execode (in zsh) + 207 [0x10e5e53ec] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1bcce [0x10e5edcce] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18707 [0x10e5ea707] 2399 doshfunc (in zsh) + 1329 [0x10e5e929d] 2399 runshfunc (in zsh) + 103 [0x10e5e96ed] 2399 wrap_private (in private.so) + 105 [0x10e87ad78] 2399 runshfunc (in zsh) + 170 [0x10e5e9730] 2399 execode (in zsh) + 207 [0x10e5e53ec] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1bcce [0x10e5edcce] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18707 [0x10e5ea707] 2399 doshfunc (in zsh) + 1329 [0x10e5e929d] 2399 runshfunc (in zsh) + 103 [0x10e5e96ed] 2399 wrap_private (in private.so) + 105 [0x10e87ad78] 2399 runshfunc (in zsh) + 170 [0x10e5e9730] 2399 execode (in zsh) + 207 [0x10e5e53ec] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1b968 [0x10e5ed968] 2399 execif (in zsh) + 366 [0x10e60cf39] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1c1cb [0x10e5ee1cb] 2399 execbuiltin (in zsh) + 2022 [0x10e5d3a8e] 2399 ??? (in zle.so) load address 0x10e7f2000 + 0x18ba3 [0x10e80aba3] 2399 execzlefunc (in zle.so) + 993 [0x10e7fd47e] 2399 doshfunc (in zsh) + 1329 [0x10e5e929d] 2399 runshfunc (in zsh) + 103 [0x10e5e96ed] 2399 wrap_private (in private.so) + 105 [0x10e87ad78] 2399 runshfunc (in zsh) + 170 [0x10e5e9730] 2399 execode (in zsh) + 207 [0x10e5e53ec] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1b968 [0x10e5ed968] 2399 execif (in zsh) + 366 [0x10e60cf39] 2399 execlist (in zsh) + 1947 [0x10e5e5ba6] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 2399 ??? (in zsh) load address 0x10e5d2000 + 0x1c1cb [0x10e5ee1cb] 2399 execbuiltin (in zsh) + 2022 [0x10e5d3a8e] 2399 ??? (in zle.so) load address 0x10e7f2000 + 0x18ba3 [0x10e80aba3] 2399 execzlefunc (in zle.so) + 780 [0x10e7fd3a9] 2399 completecall (in zle.so) + 52 [0x10e80af79] 2399 ??? (in complist.so) load address 0x10e7cf000 + 0x387f [0x10e7d287f] 2399 ??? (in zle.so) load address 0x10e7f2000 + 0x1be30 [0x10e80de30] 2399 after_complete (in complete.so) + 102 [0x10e7231a4] 2399 runhookdef (in zsh) + 54 [0x10e611bc1] 558 ??? (in complist.so) load address 0x10e7cf000 + 0x6403 [0x10e7d5403] 556 ??? (in complist.so) load address 0x10e7cf000 + 0x6406 [0x10e7d5406] 547 ??? (in complist.so) load address 0x10e7cf000 + 0x6409 [0x10e7d5409] 542 ??? (in complist.so) load address 0x10e7cf000 + 0x63fb [0x10e7d53fb] 191 ??? (in complist.so) load address 0x10e7cf000 + 0x6401 [0x10e7d5401] 5 ??? (in complist.so) load address 0x10e7cf000 + 0x63fe [0x10e7d53fe] Total number in stack (recursive counted multiple, when >=5): 7 ??? (in zsh) load address 0x10e5d2000 + 0x141c5 [0x10e5e61c5] 7 ??? (in zsh) load address 0x10e5d2000 + 0x18cc7 [0x10e5eacc7] 7 execlist (in zsh) + 1947 [0x10e5e5ba6] 5 doshfunc (in zsh) + 1329 [0x10e5e929d] 5 execode (in zsh) + 207 [0x10e5e53ec] 5 runshfunc (in zsh) + 103 [0x10e5e96ed] 5 runshfunc (in zsh) + 170 [0x10e5e9730] 5 wrap_private (in private.so) + 105 [0x10e87ad78] Sort by top of stack, same collapsed (when >= 5): ??? (in complist.so) load address 0x10e7cf000 + 0x6403 [0x10e7d5403] 558 ??? (in complist.so) load address 0x10e7cf000 + 0x6406 [0x10e7d5406] 556 ??? (in complist.so) load address 0x10e7cf000 + 0x6409 [0x10e7d5409] 547 ??? (in complist.so) load address 0x10e7cf000 + 0x63fb [0x10e7d53fb] 542 ??? (in complist.so) load address 0x10e7cf000 + 0x6401 [0x10e7d5401] 191 ??? (in complist.so) load address 0x10e7cf000 + 0x63fe [0x10e7d53fe] 5 Binary Images: 0x10e5d2000 - 0x10e651fff +zsh (97) <57263AD7-698F-3B17-98A7-8F60237D355C> /bin/zsh 0x10e71b000 - 0x10e732fff complete.so (97) /usr/lib/zsh/5.9/zsh/complete.so 0x10e749000 - 0x10e74cfff terminfo.so (97) /usr/lib/zsh/5.9/zsh/terminfo.so 0x10e761000 - 0x10e768fff parameter.so (97) /usr/lib/zsh/5.9/zsh/parameter.so 0x10e779000 - 0x10e77cff3 langinfo.so (97) /usr/lib/zsh/5.9/zsh/langinfo.so 0x10e78f000 - 0x10e796ffb zutil.so (97) /usr/lib/zsh/5.9/zsh/zutil.so 0x10e7a7000 - 0x10e7aaffb datetime.so (97) <5BBC125F-6375-3A93-B517-0167BEEAF9D0> /usr/lib/zsh/5.9/zsh/datetime.so 0x10e7bb000 - 0x10e7beff7 stat.so (97) <07560296-5DEE-38DE-8BC2-E6B873ED7316> /usr/lib/zsh/5.9/zsh/stat.so 0x10e7cf000 - 0x10e7daff3 complist.so (97) <345439F8-EB48-39A0-A3FE-6AD65221EE7D> /usr/lib/zsh/5.9/zsh/complist.so 0x10e7f2000 - 0x10e819fff zle.so (97) <4C607633-8184-3B5C-ABCA-E8BFE57519F4> /usr/lib/zsh/5.9/zsh/zle.so 0x10e83e000 - 0x10e841fff zleparameter.so (97) <64D2F12D-C626-3088-9AEC-7295859EF7AF> /usr/lib/zsh/5.9/zsh/zleparameter.so 0x10e863000 - 0x10e866fff regex.so (97) <79C134ED-199D-3503-B2F2-F1C4F2EB8056> /usr/lib/zsh/5.9/zsh/regex.so 0x10e877000 - 0x10e87afff private.so (97) /usr/lib/zsh/5.9/zsh/param/private.so 0x10e88b000 - 0x10e88efff files.so (97) <12FC4DB1-78B2-3150-B48C-7D4DC9AA5AF7> /usr/lib/zsh/5.9/zsh/files.so 0x10e8a1000 - 0x10e8a4ffb system.so (97) <122D536E-0721-3458-B5A3-2BE3DA2825FC> /usr/lib/zsh/5.9/zsh/system.so 0x10e8b5000 - 0x10e8b8fff termcap.so (97) <364894F8-6654-3A35-B9E3-E1C99F8696AA> /usr/lib/zsh/5.9/zsh/termcap.so 0x10e8f3000 - 0x10e8f6fff zpty.so (97) <46E391C0-9A42-36D4-95D5-4CEB37364189> /usr/lib/zsh/5.9/zsh/zpty.so 0x10e907000 - 0x10e90afff zselect.so (97) /usr/lib/zsh/5.9/zsh/zselect.so 0x10e956000 - 0x10e961ff7 computil.so (97) <22432C75-6B74-370C-83A0-2D101E49AF66> /usr/lib/zsh/5.9/zsh/computil.so 0x7ff80088b000 - 0x7ff8008c6ff8 libobjc.A.dylib (876) <4FC61EA7-8737-3573-8D14-F8F342B438AA> /usr/lib/libobjc.A.dylib 0x7ff8008c7000 - 0x7ff80095f5cf dyld (1.0.0 - 1066.8) <9E98A840-A3AC-31C1-AB97-829AF9BD6864> /usr/lib/dyld 0x7ff800960000 - 0x7ff800963ff8 libsystem_blocks.dylib (87) /usr/lib/system/libsystem_blocks.dylib 0x7ff800964000 - 0x7ff8009a4ff8 libxpc.dylib (2462.121.1) <6551AD74-9BD5-3FE0-8E50-0036BA40F337> /usr/lib/system/libxpc.dylib 0x7ff8009a5000 - 0x7ff8009beffe libsystem_trace.dylib (1431.100.13) <44277F21-4A11-35A7-A916-CCC625E6C34A> /usr/lib/system/libsystem_trace.dylib 0x7ff8009bf000 - 0x7ff800a55fcf libcorecrypto.dylib (1387.120.3) <6664EDE7-B08D-3D82-9A21-8A8C9F2167C8> /usr/lib/system/libcorecrypto.dylib 0x7ff800a56000 - 0x7ff800a82fff libsystem_malloc.dylib (425.100.7) /usr/lib/system/libsystem_malloc.dylib 0x7ff800a83000 - 0x7ff800acaff3 libdispatch.dylib (1415.120.2) /usr/lib/system/libdispatch.dylib 0x7ff800acb000 - 0x7ff800acdfff libsystem_featureflags.dylib (74) /usr/lib/system/libsystem_featureflags.dylib 0x7ff800ace000 - 0x7ff800b55ff7 libsystem_c.dylib (1534.100.14) <5CA0D0CF-FCDD-3180-AF7B-F137FE1E7ACA> /usr/lib/system/libsystem_c.dylib 0x7ff800b56000 - 0x7ff800bd1ff7 libc++.1.dylib (1500.65) <6E58B78C-1302-3111-B22C-B9E716235BE8> /usr/lib/libc++.1.dylib 0x7ff800bd2000 - 0x7ff800be6ff3 libc++abi.dylib (1500.65) <666C1776-A91B-369C-B122-5B3EF0C03F2A> /usr/lib/libc++abi.dylib 0x7ff800be7000 - 0x7ff800c20ff7 libsystem_kernel.dylib (8796.121.2) <84597863-2C70-3A4A-B0F1-84B39D731209> /usr/lib/system/libsystem_kernel.dylib 0x7ff800c21000 - 0x7ff800c2cfff libsystem_pthread.dylib (514.100.2) <8CB0B396-011F-31F2-8915-94CDE1ABAE84> /usr/lib/system/libsystem_pthread.dylib 0x7ff800c2d000 - 0x7ff800c50ff7 libdyld.dylib (1066.8) /usr/lib/system/libdyld.dylib 0x7ff800c51000 - 0x7ff800c5afef libsystem_platform.dylib (292.120.1.0.1) <4FF3BD2F-2167-3EE6-A55D-384703BDF1F5> /usr/lib/system/libsystem_platform.dylib 0x7ff800c5b000 - 0x7ff800c85ff7 libsystem_info.dylib (564.120.2) /usr/lib/system/libsystem_info.dylib 0x7ff8038b4000 - 0x7ff8038befff libsystem_darwin.dylib (1534.100.14) /usr/lib/system/libsystem_darwin.dylib 0x7ff803cf5000 - 0x7ff803d04ff7 libsystem_notify.dylib (312) <38B11EE0-1345-3B65-9185-D05225771F51> /usr/lib/system/libsystem_notify.dylib 0x7ff8057e7000 - 0x7ff8057fdfff libsystem_networkextension.dylib (1608.120.22) <46A36215-761C-3925-8F5B-8E9DE1517DFC> /usr/lib/system/libsystem_networkextension.dylib 0x7ff805864000 - 0x7ff80587afff libsystem_asl.dylib (395) <778B160D-96F6-3E53-9DAD-1E7ABFABD887> /usr/lib/system/libsystem_asl.dylib 0x7ff8071b9000 - 0x7ff8071c0ff7 libsystem_symptoms.dylib (1732.120.3) /usr/lib/system/libsystem_symptoms.dylib 0x7ff80a279000 - 0x7ff80a2a7ff3 libsystem_containermanager.dylib (477.120.3) /usr/lib/system/libsystem_containermanager.dylib 0x7ff80b1d1000 - 0x7ff80b1d4ff3 libsystem_configuration.dylib (1241.120.5) /usr/lib/system/libsystem_configuration.dylib 0x7ff80b1d5000 - 0x7ff80b1daffb libsystem_sandbox.dylib (1846.120.15) /usr/lib/system/libsystem_sandbox.dylib 0x7ff80bf2a000 - 0x7ff80bf2cff3 libquarantine.dylib (147.120.3) <417CE0CF-7C24-307A-86CA-39DB00F28F85> /usr/lib/system/libquarantine.dylib 0x7ff80c6d6000 - 0x7ff80c6dbfff libsystem_coreservices.dylib (144) /usr/lib/system/libsystem_coreservices.dylib 0x7ff80c9b5000 - 0x7ff80ca18fef libsystem_m.dylib (3226.100.4) /usr/lib/system/libsystem_m.dylib 0x7ff80ca19000 - 0x7ff80ca19ff3 libcharset.1.dylib (64) <35DA8CB6-45B3-31DD-9A49-38202453F878> /usr/lib/libcharset.1.dylib 0x7ff80ca1a000 - 0x7ff80ca1eff7 libmacho.dylib (1005) <98D4BB86-8B67-3F09-BA85-065D5A77F00F> /usr/lib/system/libmacho.dylib 0x7ff80ca3b000 - 0x7ff80ca46ff7 libcommonCrypto.dylib (600016.100.4) <13931C86-1F89-319A-A1E6-26B566067F97> /usr/lib/system/libcommonCrypto.dylib 0x7ff80ca47000 - 0x7ff80ca51ff7 libunwind.dylib (1500.26) /usr/lib/system/libunwind.dylib 0x7ff80ca52000 - 0x7ff80ca59ff7 liboah.dylib (289.12) /usr/lib/liboah.dylib 0x7ff80ca5a000 - 0x7ff80ca67fff libcopyfile.dylib (191.100.3) <771F14EB-5DE9-37EB-8B65-D40B94F8E9CF> /usr/lib/system/libcopyfile.dylib 0x7ff80ca68000 - 0x7ff80ca6ffff libcompiler_rt.dylib (103.1) <1C9D0D0B-947B-3BF4-BE90-C6F2B2CA07F2> /usr/lib/system/libcompiler_rt.dylib 0x7ff80ca70000 - 0x7ff80ca74ff7 libsystem_collections.dylib (1534.100.14) /usr/lib/system/libsystem_collections.dylib 0x7ff80ca75000 - 0x7ff80ca77ff7 libsystem_secinit.dylib (120.100.7) <047EF66B-D3D5-3B71-9EA5-12968A67EA5B> /usr/lib/system/libsystem_secinit.dylib 0x7ff80ca78000 - 0x7ff80ca79fff libremovefile.dylib (68) <600F8AAC-3D25-3C5A-B855-640F97D20B03> /usr/lib/system/libremovefile.dylib 0x7ff80ca7a000 - 0x7ff80ca7affb libkeymgr.dylib (31) <6254AC44-E93D-350B-966C-A4F18A78C01C> /usr/lib/system/libkeymgr.dylib 0x7ff80ca7b000 - 0x7ff80ca83ff3 libsystem_dnssd.dylib (1807.121.1) <64AFA112-0FCD-3984-AD4B-1B278BED6167> /usr/lib/system/libsystem_dnssd.dylib 0x7ff80ca84000 - 0x7ff80ca89ff7 libcache.dylib (92) <269F62C8-1D4B-333A-9109-D2F54E0639E8> /usr/lib/system/libcache.dylib 0x7ff80ca8a000 - 0x7ff80ca8bfff libSystem.B.dylib (1319.100.3) <65C3AB02-1423-3A36-9E93-88BC046941D8> /usr/lib/libSystem.B.dylib 0x7ff80cac6000 - 0x7ff80cbb7ff7 libiconv.2.dylib (64) <6BCB2527-E1D2-3A6B-9043-D72473A9B9E5> /usr/lib/libiconv.2.dylib 0x7ff9097bb000 - 0x7ff9097eaff7 libncurses.5.4.dylib (61) <83EF8E78-0A60-3478-848C-9D3062359B54> /usr/lib/libncurses.5.4.dylib ```
marlonrichert commented 10 months ago

@garthk Unfortunately, that kind of sample doesn't really tell me anything useful. Running with set -x would provide better output. What would help most, though, is if you could provide a reliable way to reproduce this.

pesterhazy commented 10 months ago

TBH I'm not seeing this problem anymore for some reason (knock on wood). Maybe removing the bunjs shell completion helped fix this as well https://github.com/marlonrichert/zsh-autocomplete/issues/632