Is there any way to prevent tmux freezing when lots of text is output to the terminal?

38

9

In a tmux session inside xterm when a programs generates lots of ouput (like a cat very_long_file the whole session in frozen for a while. Even if I press Ctrl-C nothing is interrupted. Presumably because tmux is frozen and it's not forwarding the Ctrl-C to the program generating the output. Is there any way to prevent this.

ecerulm

Posted 2012-04-27T11:31:50.723

Reputation: 563

1Horizontally splitting tmux panes (i.e. C-b %) is much more sensitive to this issue than full panes or vertically split panes. Also, running C-b d and reattaching will "unfreeze" the program, although only temporarily. There isn't really a solution unless you're willing to dig into tmux configurations. – RussellStewart – 2014-08-05T22:38:02.587

The problem is that the program wrote its output to standard out far faster than your terminal could display it. When you hit Ctrl-C, the process is indeed killed, but your terminal continues to print the buffered output. – chepner – 2012-04-30T21:16:31.363

Answers

15

The correct solution is to look at the c0-* options to tmux to try and rate-limit the output. The reason this problem exists at all is due to data being sent to the terminal faster than it can display it, so rate-limiting is the only way.

ThomasAdam

Posted 2012-04-27T11:31:50.723

Reputation: 434

@solotim Works on my tmux 1.9a, however I added set-window-option -g ... into my .tmux.conf. – polym – 2014-07-25T14:32:08.607

5Apparently, these have been removed in tmux 2.2. :( – Martin C. Martin – 2017-08-03T14:13:45.357

c0-change-trigger and c0-change-interval seem to solve the problem. The default settings are enough for me. – ecerulm – 2013-05-02T04:58:01.607

setw -g c0-change-interval 100 and setw -g c0-change-trigger 250 doesn't make any difference for me. I'm using tmux-1.8. Did I do something wrong? – solotim – 2013-08-20T10:45:41.873

20

I still have this problem in tmux 1.6-2 on Ubuntu 12.10. One workaround that I've found is to detatch from the session (prefix+d) and then reattach (tmux attach, good candidate for a quick shell alias). It looks like tmux is actually responsive under the hood---you can confirm that your process is actually killed immediately with ctrl-c---it's just the drawing that's blocking. Detatch works immediately, and when you reattach, the drawing will have skipped to the end.

Jack O'Connor

Posted 2012-04-27T11:31:50.723

Reputation: 321

Good workaround. It seems that in fact everything works, even switching between splits, it just does not get drawn. – jmiserez – 2013-10-20T12:51:33.443

1This should be tmux attach, right? – pandubear – 2014-03-06T20:55:00.677

Oops, you're right. Fixed. – Jack O'Connor – 2014-03-07T21:11:01.057

2And if you can't detach, e.g. not sure of the macro, just open a new terminal window and tmux attach. – mahemoff – 2014-04-04T22:51:55.307

5

Unfortunately the c0-* options for rate limiting have been removed as of tmux version 2.1 (changelog). As far as I know, the only way to customize rate limiting is to update the variables influencing it in the source code (tmux.h):

"READ_SIZE is the maximum size of data to hold from a pty (the event high watermark). READ_BACKOFF is the amount of data waiting to be output to a tty before pty reads will be backed off. READ_TIME is how long to back off before the next read (in microseconds) if a tty is above READ_BACKOFF."

Where you will find the defaults: (as of tmux v2.2):

#define READ_SIZE 1024
#define READ_BACKOFF 512
#define READ_TIME 100

gospes

Posted 2012-04-27T11:31:50.723

Reputation: 326

1In tmux v2.3 the indicated variables do not exist. – bergercookie – 2017-01-11T15:36:25.717

5

As far as I know there is no way to prevent it in current releases but some work is ongoing. You can find some patches on tmux's mailing list http://thread.gmane.org/gmane.comp.terminal-emulators.tmux.user/2689.

A good keyword to search the web is "flow control".

piec

Posted 2012-04-27T11:31:50.723

Reputation: 520

2why the patch is not validated in the main branch? this issue is the most important reason I still use gnu_screen. – solotim – 2012-08-15T06:51:59.803

4

The answer https://superuser.com/a/589896/311481 works fine. I use the following values:

setw -g c0-change-trigger 10
setw -g c0-change-interval 250

Another tip: if you use ssh within tmux, use mosh instead: http://mosh.mit.edu/ It behaves smarter as to displaying programs' output. It tries to display the last screen state dropping intermediates when appropriate. So tmux will never freeze if lots of output is generated within its panes with mosh sessions inside.

Unlike SSH, mosh's UDP-based protocol handles packet loss gracefully, and sets the frame rate based on network conditions. Mosh doesn't fill up network buffers, so Control-C always works to halt a runaway process.

Because SSP [State Synchronization Protocol that mosh uses] works at the object layer and can control the rate of synchronization (in other words, the frame rate), it does not need to send every byte it receives from the application. That means Mosh can regulate the frames so as not to fill up network buffers, retaining the responsiveness of the connection and making sure Control-C always works quickly. Protocols that must send every byte can't do this.

user2683246

Posted 2012-04-27T11:31:50.723

Reputation: 261

0

Try different terminal emulator. On RedHat 6.5, the konsole (KDE) does not have the freezing issue (tmux 2.3 and master); however, xterm and gnome-terminal both experience bad freezing.

kko

Posted 2012-04-27T11:31:50.723

Reputation: 1

tmux 2.2 however works fine without freezing issue on all three terminal emulators. – kko – 2017-02-01T06:19:19.140