zellij
zellij copied to clipboard
rename-tab is not thread-safe
Issues with the Zellij UI / behavior / crash
Issue description
zellij action rename-tab ... is not working as expected when called in parallel. The text will be concatenated.
Minimal reproduction
Invoke the command with a loop async at least two times.
Screenshot
The tab-name is .doom.d.doom.d instead of just .doom.d.
From inside a zellij session, this can be reproduced by running the following in the terminal (assuming bash):
for i in $(seq 1 10); do
zellij action rename-tab test &
done
My best guess is that, at the most specific level, the problem is with update_active_tab_name being called from multiple threads:
https://github.com/zellij-org/zellij/blob/226f5dc854e26ddfa4dd087f6e4cb99b0230da74/zellij-server/src/screen.rs#L1735
The only place it is called is later in that same file, inside screen_thread_main's loop:
https://github.com/zellij-org/zellij/blob/226f5dc854e26ddfa4dd087f6e4cb99b0230da74/zellij-server/src/screen.rs#L4040-L4044
Which is surprising to me based on some (probably inaccurate) assumptions I'm making about the architecture. The command goes from the client to the thread bus, then the thread bus sends it to the screen. I would expect that the thread bus is just responsible for sending the command to the correct thread, with one thread per session, but if that were true then we shouldn't have this problem. Based on the top of the main loop it looks like events are being processed sequentially (even though they might be queued in parallel) and should be fully handled before moving onto the next one:
https://github.com/zellij-org/zellij/blob/226f5dc854e26ddfa4dd087f6e4cb99b0230da74/zellij-server/src/screen.rs#L3117-L3127
Also, when running the command from https://github.com/zellij-org/zellij/issues/4199#issuecomment-2909938895 some of the iterations will print that there is no active session - probably an unrelated issue.