ddollar / foreman

Manage Procfile-based applications

Home Page:http://ddollar.github.com/foreman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Doesn't output logging from a Ruby process until Ctrl+C

ZimbiX opened this issue · comments

If your Procfile lists a Ruby process, no output from it will be shown until you use Ctrl+C to stop foreman, at which point you see everything that should have been shown before.

I've looked into this a bit, and the problem relates to using IO.select in the engine. It's supposed to return a list of the processes that are ready to be read from, but for some reason, it excludes the ruby process until foreman starts shutting down.

Changing the timeout in the IO.select call to 1 does not help; it still returns nil every time.


Minimal test case:

Procfile:

rb: ruby -e 'loop { puts Time.now; sleep 1 }'

Run:

$ foreman start      
16:55:40 rb.1   | started with pid 5755
^C16:55:44 system | SIGINT received, starting shutdown
16:55:44 rb.1   | -e:1:in `sleep': Interrupt
16:55:44 rb.1   | 	from -e:1:in `block in <main>'
16:55:44 rb.1   | 	from -e:1:in `loop'
16:55:44 rb.1   | 	from -e:1:in `<main>'
16:55:44 rb.1   | 2018-05-22 16:55:40 +1000
16:55:44 rb.1   | 2018-05-22 16:55:41 +1000
16:55:44 rb.1   | 2018-05-22 16:55:42 +1000
16:55:44 rb.1   | 2018-05-22 16:55:43 +1000
16:55:44 rb.1   | 2018-05-22 16:55:44 +1000
16:55:45 system | sending SIGTERM to all processes
16:55:45 rb.1   | terminated by SIGINT

My system:

$ ruby --version
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
$ foreman --version
0.84.0

Nevermind! It turns out Ruby defaults to buffered output, and can be make synchronous with STDOUT.sync = true.

commented

I have the same problem on Rails, I wonder how it could be fixed?