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

@ close-tab remote-control does not appear to run synchronously #5895

Closed
salmankhilji opened this issue Jan 17, 2023 · 10 comments
Closed

@ close-tab remote-control does not appear to run synchronously #5895

salmankhilji opened this issue Jan 17, 2023 · 10 comments
Labels

Comments

@salmankhilji
Copy link

Describe the bug
The @ close-tab remote-control does not appear to run synchronously. The issue is that if I put two separate @ close-tab remote-control commands immediately after one another, the second command seems to affect the first one.

To Reproduce

  1. Save the following contents as a file named /tmp/workrc:
    kitty @ set-tab-title $'\U1f527'
    kitty @ env WORKDIR=/tmp
    for i in {1..5}; do kitty @ launch --tab-title tab_$i --type tab; done
    kitty @ close-tab --match env:WORKDIR
    kitty @ close-tab --self
    (Because I am not running with the fix for kitty @ close-tab --match all is broken #5894 yet, I am choosing to close all tabs in two steps.)
  2. Launch kitty like this: i=0; while :; do kitty --config NONE -o 'allow_remote_control yes' bash --rcfile /tmp/workrc; sleep 0.1; (( ++i )); echo iteration $i; done.

Observed Behavior

At some random point in time, kitty fails to close all tabs and the script hangs. Probably because the second @ close-tab affected the first one?

In the screenshot below, observe that kitty is sitting idle with tab_1 in iteration 9. (kitty should have exited.)

kitty-bug

Environment details

kitty 0.26.5 () created by Kovid Goyal
Linux byteevo 5.15.0-58-generic #64~20.04.1-Ubuntu SMP Fri Jan 6 16:42:31 UTC 2023 x86_64
Ubuntu 20.04.5 LTS byteevo /dev/tty

DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=20.04
DISTRIB_CODENAME=focal
DISTRIB_DESCRIPTION="Ubuntu 20.04.5 LTS"
Running under: X11
Frozen: True
Paths:
  kitty: /home/precor/.local/kitty.app/bin/kitty
  base dir: /home/precor/.local/kitty.app/lib/kitty
  extensions dir: /home/precor/.local/kitty.app/lib/kitty-extensions
  system shell: /bin/bash
Loaded config overrides:
  allow_remote_control yes

Config options different from defaults:
allow_remote_control yes

Important environment variables seen by the kitty process:
	PATH                                /home/precor/.nvm/versions/node/v14.18.2/bin:/opt/qt/5.15.2/gcc_64/bin:/home/precor/.local/flutter/bin:/home/precor/.pub-cache/bin:/home/precor/Android/Sdk/build-tools/30.0.3:/home/precor/Android/Sdk/emulator:/home/precor/Android/Sdk/platform-tools:/home/precor/Android/Sdk/cmdline-tools/latest/bin:/home/precor/.local/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/snap/bin
	LANG                                en_US.UTF-8
	SHELL                               /bin/bash
	DISPLAY                             :0
	USER                                precor
	XDG_CONFIG_DIRS                     /etc/xdg/xdg-ubuntu:/etc/xdg
	XDG_MENU_PREFIX                     gnome-
	XDG_SESSION_DESKTOP                 ubuntu
	XDG_SESSION_TYPE                    x11
	XDG_CURRENT_DESKTOP                 ubuntu:GNOME
	XDG_SESSION_CLASS                   user
	XDG_RUNTIME_DIR                     /run/user/1000
	XDG_DATA_DIRS                       /usr/share/ubuntu:/usr/local/share/:/usr/share/

Additional context

  1. Running kitty nightly from yesterday.
  2. You can repeat after adding a sleep 0.5 in between the two @ close-tab commands within workrc to calm down any potential race condition. My observation is that this bug then does not reproduce.
@kovidgoyal
Copy link
Owner

Doesnt repro for me running it with 130 iterations (from master). Does it still repro if you add --no-response to the @ close-tab command?

@kovidgoyal
Copy link
Owner

Basically, what I suspect is happening is in your system kitty is shutting down before the response is written for the close-tab command. There is no good way to fix this, I would suggest just using --no-response for @ close-tab if you expect it to potentially cause kitty to quit.

@salmankhilji
Copy link
Author

Yes, the bug still reproduces with --no-response.

Modified workrc like this:

kitty @ set-tab-title $'\U1f527'
kitty @ env WORKDIR=/tmp
for i in {1..5}; do kitty @ launch --tab-title tab_$i --type tab; done
kitty @ close-tab --match env:WORKDIR --no-response
kitty @ close-tab --self --no-response

Built kitty from source with master at 821f52a7 since nightly is broken at the moment.

@kovidgoyal
Copy link
Owner

Doesnt reproduce for me at all, with the original or modified script. Add set -o verbose to see which command is hanging.

@kovidgoyal
Copy link
Owner

Actually from your screenshot its probably launch not getting a response, try adding --no-response to launch to confirm

@salmankhilji
Copy link
Author

kitty @ set-tab-title $'\U1f527'
kitty @ env WORKDIR=/tmp
for i in {1..5}; do kitty @ launch --tab-title tab_$i --type tab --no-response; done
kitty @ close-tab --match env:WORKDIR --no-response
kitty @ close-tab --self --no-response

Lucky enough to get kitty to hang on the very first iteration:

$ i=0; while :; do kitty --dump-commands --config NONE -o 'allow_remote_control yes' bash --rcfile /tmp/workrc; sleep 0.1; (( ++i )); echo iteration $i; done
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"set-tab-title","version":[0,26,0],"kitty_window_id":1,"payload":{"title":"\ud83d\udd27"}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"env","version":[0,26,0],"kitty_window_id":1,"payload":{"env":{"WORKDIR":"/tmp"}}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"launch","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"tab_title":"tab_1","type":"tab","location":"default","stdin_source":"none","logo_alpha":-1}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"launch","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"tab_title":"tab_2","type":"tab","location":"default","stdin_source":"none","logo_alpha":-1}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"launch","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"tab_title":"tab_3","type":"tab","location":"default","stdin_source":"none","logo_alpha":-1}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"launch","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"tab_title":"tab_4","type":"tab","location":"default","stdin_source":"none","logo_alpha":-1}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"launch","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"tab_title":"tab_5","type":"tab","location":"default","stdin_source":"none","logo_alpha":-1}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"close-tab","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"match":"env:WORKDIR"}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
screen_set_8bit_controls 0
screen_save_modes
screen_decsace 0
screen_reset_mode 4 0
screen_reset_mode 1 1
screen_reset_mode 5 1
screen_reset_mode 2004 1
screen_reset_mode 1004 1
screen_reset_mode 1000 1
screen_reset_mode 1002 1
screen_reset_mode 1003 1
screen_reset_mode 1005 1
screen_reset_mode 1006 1
screen_set_mode 8 1
screen_set_mode 7 1
screen_set_mode 25 1
screen_push_key_encoding_flags 31
screen_handle_cmd 64 {"cmd":"close-tab","version":[0,26,0],"no_response":true,"kitty_window_id":1,"payload":{"self":true}}
screen_pop_key_encoding_flags 1
screen_save_cursor
screen_restore_modes
screen_pop_colors 0
process_cwd_notification 7 kitty-shell-cwd://byteevo/home/precor
shell_prompt_marking k;start_kitty
shell_prompt_marking A
shell_prompt_marking k;end_kitty
draw precor@byteevo:~$ 
shell_prompt_marking k;start_suffix_kitty
screen_set_cursor 5 32
set_title ~
shell_prompt_marking k;end_suffix_kitty
handle_remote_print 64 aWdub3JlYm90aCBvciBpZ25vcmVzcGFjZSBwcmVzZW50IGluIGJhc2ggSElTVENPTlRST0wgc2V0dGluZywgc2hvd2luZyBydW5uaW5nIGNvbW1hbmQgaW4gd2luZG93IHRpdGxlIHdpbGwgbm90IGJlIHJvYnVzdAo=}
ignoreboth or ignorespace present in bash HISTCONTROL setting, showing running command in window title will not be robust
process_cwd_notification 7 kitty-shell-cwd://byteevo/home/precor
shell_prompt_marking k;start_kitty
shell_prompt_marking A
shell_prompt_marking k;end_kitty
set_title precor@byteevo: ~
set_icon precor@byteevo: ~
select_graphic_rendition 1 
select_graphic_rendition 92 
draw precor@byteevo
select_graphic_rendition 0 
draw :
select_graphic_rendition 1 
select_graphic_rendition 94 
draw ~
select_graphic_rendition 0 
draw $ 
shell_prompt_marking k;start_suffix_kitty
screen_set_cursor 5 32
set_title ~
shell_prompt_marking k;end_suffix_kitty

@kovidgoyal
Copy link
Owner

Then I'm out of ideas without being able to reproduce there isnt much
more I can say.

@kovidgoyal
Copy link
Owner

Oh and see if theis commit helps: 0c7b4df

@salmankhilji
Copy link
Author

I pulled the changes from 68a0064 and built kitty from source. The issue still reproduces. I think this and issue #5890 are probably due to the same root cause: remote control command somehow fail to complete.

I will work on attaching a script to reproduce the bug.

@kovidgoyal
Copy link
Owner

kovidgoyal commented Jan 18, 2023

It doesnt reproduce with --no-response (on all the @ commands) anymore, at least for me. it will still reproduce rarely without --no-response.

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

No branches or pull requests

2 participants