tsl0922 / ttyd

Share your terminal over the web
https://tsl0922.github.io/ttyd
MIT License
8.18k stars 898 forks source link

There are some pauses of about 5 seconds while trzsz is transmitting files. #1239

Closed lonnywong closed 12 months ago

lonnywong commented 1 year ago

Describe the bug The trzsz ( trz / tsz ) is slow due to some pauses of about 5 seconds.

To Reproduce Steps to reproduce the behavior:

  1. Install trzsz ( trz / tsz ) and ttyd on the server.
  2. Run ttyd --writable -t enableTrzsz=true bash
  3. Open the browser, press F12, click Network
  4. Open http://localhost:7681
  5. Type trz command, and choose some files to upload
  6. Watch the data flow of ws.

Expected behavior No pauses while trzsz is transferring files, and the speed should be 1MB/s at least.

Screenshots

Screenshot 2023-11-05 at 19 40 51

Environment:

lonnywong commented 1 year ago

@tsl0922 If add --ping-interval 1, trz is much faster, but it still keeps pausing for one second.

ttyd --writable -P 1 -t enableTrzsz=true bash
lonnywong commented 1 year ago

When the issue occurs, the behavior is as follows:

  1. trz prints some output.
  2. process_read_cb calls lws_callback_on_writable ( no delay ): https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L92
  3. LWS_CALLBACK_SERVER_WRITEABLE gets called ( no delay ): https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L253
  4. pss->pty_buf is not null: https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L275
  5. It calls lws_write ( no delay ): https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L176
  6. But the browser client doesn't receive the message for now. Something goes wrong.
  7. About 5 seconds later, LWS_CALLBACK_SERVER_WRITEABLE gets called again: https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L253
  8. pss->pty_buf is null: https://github.com/tsl0922/ttyd/blob/272f2f8de150454fca7895913bd85c60a6c3ac2e/src/protocol.c#L275
  9. lws_write is not called again, but the browser client receive the message now. Don't know the client receive it before LWS_CALLBACK_SERVER_WRITEABLE, or after it.

The issue may relate to https://github.com/warmcat/libwebsockets/issues/1158 .

lonnywong commented 1 year ago

@tsl0922 Are there any features of ttyd that depends on -DLWS_WITHOUT_EXTENSIONS=OFF? https://github.com/tsl0922/ttyd/blob/5aa2da4bd36858a287224e41a14cc3e6e6a47616/scripts/cross-build.sh#L108

If you delete the line, the issue is solved. But if there are features that depends on it, we need to fix this: https://github.com/warmcat/libwebsockets/issues/1158#issuecomment-1806741778

tsl0922 commented 1 year ago

1179

lonnywong commented 1 year ago

1179

Well, we can't get around it.

tsl0922 commented 1 year ago

Do you think it's related to data compression? I think we can add a flag for it in ttyd.

lonnywong commented 1 year ago

We may need a flush somewhere. https://github.com/warmcat/libwebsockets/issues/1158#issuecomment-1812446179

lonnywong commented 1 year ago

Update: https://github.com/warmcat/libwebsockets/issues/1768#issuecomment-1813536315