Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails freezes when searching through tmux output buffer

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?

like image 882
michaelmwu Avatar asked Dec 18 '12 00:12

michaelmwu


1 Answers

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.
like image 117
Chris Johnsen Avatar answered Oct 18 '22 16:10

Chris Johnsen