-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
4.0.1->4.1.0, Rails logs flushing incorrectly #1906
Comments
Definitely related to #1837. Please post your Puma config file, if any. |
FWIW everything does seem to work fine with a "normal" Puma config on Heroku, so we need to figure out what you're doing differently. |
My Puma config file is quite standard. I think it's the one that came default with Rails 6.
|
Some other info that hopefully is useful: Env variable My
The log in the first post shows something interesting. NewRelic starts sending out logs before Puma shows its startup message. But the last line in the NewRelic log spam is omited, and only shown after the app is closed. |
I can see the same behavior with Mastodon, which has pretty much the same code in its Rails configuration: ActiveSupport::Logger.new(STDOUT).tap do |logger|
logger.formatter = config.log_formatter
config.logger = ActiveSupport::TaggedLogging.new(logger)
end Reverting #1837 fixes it |
This error seems to cause also |
I'm seeing this as well. I've traced it to this commit: 70b28bb My hunch is that due to that commit, output is no longer being flushed before I'm planning on opening an issue and PR if I am able to verify this. |
@mattbrictson yes. That is exactly what is happening ;) |
I dug into this a little more. Puma reopens STDOUT and STDERR to Here is where the streams are being reopened: Lines 27 to 28 in 3b34c3f
But that doesn't affect the dup'ed ones created here: Lines 32 to 33 in 3b34c3f
So the upshot is that I can't find an easy fix besides just reverting #1837. @montanalow any ideas? |
@mattbrictson oh, I think that monkey patching of It doesn't look like it has been meaningful touched since 2013: https://github.com/puma/puma/commits/v4.1.0/lib/puma/daemon_ext.rb And according to a comment on the commit, 775534c, the bug in Ruby is solved. I tested the repro from the bug with the lowest Ruby version Puma tests with: $ docker run -it --rm -v $(pwd):/app ruby:2.2.10 bash
root@4ab5c614136e:/# ls /app
repro.rb
root@4ab5c614136e:/# cat /app/repro.rb
r1, w1 = IO.pipe
r2, w2 = IO.pipe
t = Thread.new {
puts "start"
w1.write "x"
IO.select([r2])
puts "alive"
}
IO.select([r1])
Process.daemon true, true # comment this line out and everything works
puts Process.pid
w2.write "x"
t.join
puts "done"
root@4ab5c614136e:/# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.2 0.1 20244 3216 pts/0 Ss 20:45 0:00 bash
root 8 0.0 0.1 17500 2104 pts/0 R+ 20:45 0:00 ps aux
root@4ab5c614136e:/# ruby /app/repro.rb
start
root@4ab5c614136e:/# 15
done
root@4ab5c614136e:/# ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
root 1 0.0 0.1 20244 3216 pts/0 Ss 20:45 0:00 bash
root 18 0.0 0.1 17500 2064 pts/0 R+ 20:46 0:00 ps aux |
@dentarg I tried removing the |
This makes sense as an issue. Puma <4.1.0 was previously forcing all STDOUT to be sync. When Rails dropped heroku/rails_stdout_logging#31 The fix may be to require this gem for heroku configurations: |
@pauloddr I had a similar issue with Puma no longer flushing output correctly after updating recently but was able to workaround it by adding |
I'm going to revert #1837. We need to stop messing with STDOUT.sync eventually but we'll revert until someone takes another crack at it. |
4.1.1 will be out within the hour and fix this. |
Steps to reproduce
I can't seem to reproduce the issue locally, so I'll try my best to explain what happened.
Deployed an existing Rails app on Heroku after upgrading Puma from 4.0.1 to 4.1.0.
Made some requests. App works fine. Checked the logs.
Request logs were absent. (Heroku Router logs were present.)
Rebooted the application and all previous request logs were dumped at once with the wrong times (app shutdown time).
Expected behavior
Request logs should appear right after they happen.
Actual behavior
Request logs are dumped after the application exits instead, preventing real-time logging and breaking log times.
Reverting to Puma 4.0.1 restores intended behavior.
System configuration
Ruby version: 2.6.1
Rails version: 6.0.0.rc2
Puma version: 4.1.0
Log Dump
The text was updated successfully, but these errors were encountered: