ble.sh: [kitty] Hangs on exit
ble version: Bash version:
GNU bash, version 5.2.26(1)-release (x86_64-pc-linux-gnu) [Arch Linux]
ble.sh, version 0.4.0-devel4+838b4652 (noarch) [git 2.43.0, GNU Make 4.4.1, GNU Awk 5.3.0, API 4.0, PMA Avon 8-g1, (GNU MPFR 4.2.1, GNU MP 6.3.0)]
starship, version 1.17.1 (rustc 1.75.0 (82e1608df 2023-12-21) (Arch Linux rust 1:1.75.0-1), 2024-01-03 07:54:53 +00:00)
zoxide, version 0.9.2 (/usr/bin/zoxide)
atuin, version 17.2.1 (/usr/bin/atuin)
locale: LANG=en_US.UTF-8 LC_TIME=en_DK.UTF-8
terminal: TERM=xterm-kitty wcwidth=15.0-west/15.1-2+ri, kitty:0 (1;4000;31)
When I type exit
and press Enter, sometimes (not always) ble.sh just hangs here:
It displays this and then nothing happens.
The kitty tab is not closed.
About this issue
- Original URL
- State: closed
- Created 5 months ago
- Reactions: 2
- Comments: 42 (22 by maintainers)
Just updated, I will let you know if this fixes it. Thank you!!!
I discovered that it is possible to add
O_CLOEXEC
to the specified file descriptor in pure Bash. It hacks the file descriptor that Bash internally uses to back up the original file descriptor for redirection. I implemented it in commit 785267e18c81ada61fb26a346339613a8a8b04e6. The trick only works in Bash >= 4.0, but I think it should be fine for most users. Now I think the hanging tab would happen less.@10b14224cc @ribru17 Could you update
ble.sh
by runningble-update
and use it for a while to see if the situation changes?I think the culprit in @10b14224cc’s environment is
hyprpaper
. First, there are only two processes that started after the hanging session starts (21265) and before runningps uxf
(24438):The Bash process on the second line of the output is another tab where
ps uxf
was run. Then, the only process ishyprpaper
.Second,
hyprpaper
is also a Wayland application similar towl-copy
. They probably lose their controlling terminal onwl_display_connect
. Both programs call this function to initialize its Wayland session.Third,
hyprpaper
has so-called IPC mode (which I guess stands for the interprocess communication mode?), which is enough to suspect that it launches a background worker. In fact, there seems to be a process ofhyprpaper
running in background in @10b14224cc’sps uxf
result.Also, I think now I can explain why the problem comes out when
ble.sh
is used.ble.sh
internally backs up the file descriptor of the TTY to different numbers, so even if the standard streams are closed by the background process, the backed-up descriptors remain. What is needed is to specifyO_CLOEXEC
to the backed-up file descriptors so that they are automatically closed in the child processes on their startup, but there is no obvious way to specifyO_CLOEXEC
at the shell script level.The author of
wl-copy
seems to refuse to close the TTY. The author’s thought is explained in https://github.com/bugaevc/wl-clipboard/pull/110#issuecomment-785153532. That explanation contains the following phrase:This means that
wl-copy
has a background process, which partly answers my question. Then, the author tries to keepstderr
of the background process connected to the TTY for error logging, but it seems a bit strange to use the TTY for error logging of a background process. A background process should save its error, if any, to a log file instead of the TTY where another application might be in the foreground.Ah. I see. So it’s not necessarily used as a command-line tool but can be a background worker for another program.