summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStan Hu <stanhu@gmail.com>2018-09-11 22:55:01 -0700
committerStan Hu <stanhu@gmail.com>2018-09-11 23:12:23 -0700
commit95e292780492ea764328566503ebefcae8a170f3 (patch)
tree3e79f94ded694e27336e059063463e2018cb83c5
parente5b6e8e2550e203978cd25d3e07ca468b4d06c91 (diff)
downloadgitlab-shell-95e292780492ea764328566503ebefcae8a170f3.tar.gz
Fix newlines not appearing between new log entriessh-fix-nonatomic-puts
In https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/5017, we observed that lots of log messages were being dropped by Fluentd due to missing newlines. This occurs because there is a bug in Ruby where IO#puts calls write() twice: once to write the main text, and another to write the newline (https://bugs.ruby-lang.org/issues/14042). In a highly concurrent environment like GitLab.com, this can lead to interleaved newlines. A workaround is to use `IO#print` and append the newline ourselves. Closes https://gitlab.com/gitlab-com/gl-infra/infrastructure/issues/5017
-rw-r--r--lib/gitlab_logger.rb5
1 files changed, 3 insertions, 2 deletions
diff --git a/lib/gitlab_logger.rb b/lib/gitlab_logger.rb
index ed169f7..67f6030 100644
--- a/lib/gitlab_logger.rb
+++ b/lib/gitlab_logger.rb
@@ -68,9 +68,10 @@ class GitlabLogger
case log_format
when 'json'
- log_file.puts format_json(data)
+ # Don't use IO#puts because of https://bugs.ruby-lang.org/issues/14042
+ log_file.print("#{format_json(data)}\n")
else
- log_file.puts format_text(data)
+ log_file.print("#{format_text(data)}\n")
end
end