28

I'm running Rails 3.2.6 in development mode using tmux. When I scroll through the output buffer of the Rails server (run using rails s) using tmux, the server freezes and doesn't process any requests. When I escape scrollback mode, the server starts working properly again.

How can I set up my server to keep processing requests while I'm looking through the output buffer?

michaelmwu
  • 343
  • 3
  • 8

1 Answers1

35

If you want to pause and examine at some particular sequence of log messages while your server continues processing requests, it is probably best to directly view the log files instead; you might use less -R log/development.log.

While a tmux pane is in “copy mode” (the mode used to view a pane’s history), tmux does not read any output from the processes running in the pane’s tty. If the processes continue to write output to the tty, then the OS’s tty buffer will eventually fill. When a program writes to a tty with a full buffer, it causes the process to block so that the buffer does not overflow; this is what causes your server to temporarily stop processing requests.

The timeline looks like this:

  1. You enter copy mode to view some old output.
    tmux stops reading from the tty.
  2. Your Rails server continues to write to the tty as it handles ongoing requests.
    The OS absorbs these writes into a tty buffer of some limited size.
  3. Eventually, the OS tty buffer fills up and causes further writes to the tty to block.
    This is where the Rails server “freezes”; it is stuck waiting for the OS to return from (e.g.) a write(2) call it made to display a log message.
  4. You exit copy mode.
    tmux resumes reading from the tty, draining the buffered output and accepting new output.
Chris Johnsen
  • 214,407
  • 26
  • 209
  • 186
  • 4
    Besides not using tmux, is there any way around this issue? – justingordon Nov 02 '13 at 22:23
  • @justingordon: If a program running in a *tmux* pane writes enough while the pane is in “copy mode”, then it will eventually block. If you need to review the output of a chatty, long running process it is better to send the output to a log file and use something like `less` to view that instead of using *tmux*’s “copy mode”. – Chris Johnsen Nov 03 '13 at 02:23
  • Running txmux in iTerm2 is a way around this issue. – justingordon Nov 03 '13 at 07:47
  • @justingordon: Do you mean using the *tmux* integration offered by *iTerm* 2? I do not use it, but that may work if *iTerm* keeps its own copy of the pane’s history that it uses for viewing the “scrollback”. It still holds that using “copy mode” can cause a process that writes to the tty to block. – Chris Johnsen Nov 03 '13 at 09:30
  • As a workaround, I use tail log/development.log -F to look at the logs while rails runs in another pane. – hakunin Jul 13 '17 at 15:58