sorenisanerd / gotty

Share your terminal as a web application
MIT License
2.17k stars 137 forks source link

Zmodem transfers/cancellations hang terminal #46

Open dmartin opened 2 years ago

dmartin commented 2 years ago

What version of GoTTY are you using (gotty --version)?

1.4.0

What operating system and browser are you using?

Ubuntu 22.04, Chrome

What did you do?

If possible, please provide the command you ran.

./gotty -p 7681 -w bash

What did you expect to see?

Action Expected Behavior
rz, cancel upload (close modal) rz exits and terminal prompt advances
sz <filename>, click Accept File is transferred to browser, terminal prompt advances
sz <filename>, click Decline sz exits and terminal prompt advances
sz <filename>, close modal sz exits and terminal prompt advances

What did you see instead?

If possible, please provide the output of the command and your browser's console output.

Action Observed Behavior
rz, cancel upload (close modal) Prompt is stuck on rz waiting to receive.**B0100000023be50
sz <filename>, click Accept File is transferred to browser, terminal prompt is stuck on **B00000000000000, JavaScript console reports errors: Uncaught PROTOCOL: Only thing after ZFIN should be “OO” (79,79), not: ... at zsession.js:563
sz <filename>, click Decline Modal displays "Skipping..." until manually closed, JavaScript console reports errors: Uncaught PROTOCOL: Only thing after ZFIN should be “OO” (79,79), not: ..., sz: skipped: <filename> is written to terminal but prompt is stuck
sz <filename>, close modal Prompt is stuck on **B00000000000000 until it eventually times out
sorenisanerd commented 2 years ago

Ugh. That does not look great. :( I wonder if all of these are caused by the same core issue. It sounds like I'm not resetting the Zmodem state correctly at the right times.

sorenisanerd commented 2 years ago

Thank you very much for this bug report. I really appreciate your attention to detail. It was very, very helpful.

Here's a test build: https://github.com/sorenisanerd/gotty/actions/runs/2976008354

Can you take it for a spin? Thanks!

dmartin commented 2 years ago

Hi @sorenisanerd, it seems like there are some improvements with that build, still seeing some issues with sz handling though.

sorenisanerd commented 2 years ago

Ugh. It works for me. I guess I'm looking for a race condition. Thanks for checking! I'll get back to you when I've dug deeper :)

dmartin commented 2 years ago

Thanks for looking into it, but please don't stress too much on my account! This is not blocking any work for me, just something I ran into while testing out terminal-sharing tools.

luohailong commented 2 years ago

Same problem

sorenisanerd commented 2 years ago

I've spent a lot of time trying to reliably reproduce this. It happens sometimes, but I've been unable to trigger it while running either gotty, bash, or sz under strace. I've tried many other ways to observe what is happening, but whenever I get close, it stops happening. What I have been able to observe is that occasionally, the terminating OO from sz gets swallowed SOMEWHERE, but it's a bit of a mystery where or why. The gotty process on the server simply does not see it, so it can't pass it along to the frontend.

Are you doing anything interesting with your command prompt? $PS1 trickery? PROMPT_COMMAND doing anything cool? I don't know. I'll keep digging, but even if this turns out to be a bug in lrzsz or something, we have to support existing versions of it, so I'll whip up a patch for zmodemjs to fix it.

Fwiw, we're not alone: https://github.com/tsl0922/ttyd/issues/239 https://github.com/tsl0922/ttyd/issues/279 https://github.com/Eugeny/tabby/issues/6259 https://github.com/cferdinandi/tabby/issues/132 https://github.com/Eugeny/tabby/issues/5196 https://github.com/trzsz/tabby-trzsz/issues/2 https://github.com/Eugeny/tabby/issues/5132