Skip to content

Commit 2831982

Browse files
committed
Tau - print log directly to file rather than stdout
We now pass the log file path to Tau on boot which then uses it to directly pipe the logs towards. This is instead of the previous approach which piped stdout from Tau to Daemon and then Daemon wrote it to the log file. This appears to fix an issue with the kill switch in the case where the Daemon process was killed. In certain circumstances (observed on both Windows and macOS) it was possible to block the kill switch from working by killing the Daemon which was working with the stdout. It's possible the BEAM can't detect when something consuming stdout has disappeared and therefore blocks. Printing to a file rather than stdout appears to stop this blocking from happening and the kill switch seems to work as expected regardless of how the Daemon process is terminated.
1 parent 2372e15 commit 2831982

File tree

5 files changed

+32
-11
lines changed

5 files changed

+32
-11
lines changed

app/server/beam/tau/boot-win.bat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ set TAU_IN_PORT=%5%
1313
set TAU_API_PORT=%6%
1414
set TAU_SPIDER_PORT=%7%
1515
set TAU_DAEMON_PORT=%8%
16+
set TAU_LOG_PATH=%9%
1617

1718
IF NOT DEFINED MIX_ENV SET "MIX_ENV=prod"
1819

app/server/beam/tau/config/config.exs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import Config
2+
3+
config :tau,
4+
handle_otp_reports: true,
5+
handle_sasl_reports: true
6+
7+
config :logger,
8+
backends: [{LoggerFileBackend, :error_log}]
9+
10+
config :logger, :error_log,
11+
path: System.get_env("TAU_LOG_PATH"),
12+
level: :info

app/server/beam/tau/mix.exs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ defmodule Tau.MixProject do
2121
defp deps do
2222
[
2323
{:rustler, "~> 0.22.0"},
24+
{:logger_file_backend, "~> 0.0.10"}
2425
# {:dep_from_hexpm, "~> 0.3.0"},
2526
# {:dep_from_git, git: "https://github.com/elixir-lang/my_dep.git", tag: "0.1.0"}
2627
]

app/server/beam/tau/mix.lock

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
%{
2+
"logger_file_backend": {:hex, :logger_file_backend, "0.0.12", "5afaa76a0cb6123cd19900c0f414044cfc46c24c6a1b80842a9b0e7f6c755e57", [:mix], [], "hexpm", "7335cc4e186a3804f9d3651f2fb42243a11748f1e384421bdd17623ed53fed79"},
23
"rustler": {:hex, :rustler, "0.22.0", "e2930f9d6933e910f87526bb0a7f904e32b62a7e838a3ca4a884ee7fdfb957ed", [:mix], [{:toml, "~> 0.5.2", [hex: :toml, repo: "hexpm", optional: false]}], "hexpm", "01f5989dd511ebec09be481e07d3c59773d5373c5061e09d3ebc3ef61811b49d"},
34
"toml": {:hex, :toml, "0.5.2", "e471388a8726d1ce51a6b32f864b8228a1eb8edc907a0edf2bb50eab9321b526", [:mix], [], "hexpm", "f1e3dabef71fb510d015fad18c0e05e7c57281001141504c6b69d94e99750a07"},
45
}

app/server/ruby/bin/daemon.rb

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -394,8 +394,11 @@ def initialize(cmd, args, log_path)
394394
@pid = nil
395395
@args = args.map {|el| el.to_s}
396396
@cmd = cmd
397-
@log_file = File.open(log_path, 'a')
398-
raise "Unable to create log file at path: #{log_path}" unless @log_file
397+
if log_path
398+
@log_file = File.open(log_path, 'a')
399+
raise "Unable to create log file at path: #{log_path}" unless @log_file
400+
end
401+
399402
begin
400403
boot
401404
rescue StandardError => e
@@ -416,13 +419,15 @@ def boot
416419
Util.log "#{@cmd} #{@args.join(' ')}"
417420
@stdin, @stdout_and_err, @wait_thr = Open3.popen2e @cmd, *@args
418421
@pid = @wait_thr.pid
419-
@io_thr = Thread.new do
420-
@stdout_and_err.each do |line|
421-
begin
422-
@log_file << line
423-
@log_file.flush
424-
rescue IOError
425-
# don't attempt to write
422+
if @log_file
423+
@io_thr = Thread.new do
424+
@stdout_and_err.each do |line|
425+
begin
426+
@log_file << line
427+
@log_file.flush
428+
rescue IOError
429+
# don't attempt to write
430+
end
426431
end
427432
end
428433
end
@@ -639,7 +644,8 @@ def initialize(ports)
639644
in_port,
640645
api_port,
641646
spider_port,
642-
daemon_port
647+
daemon_port,
648+
Paths.tau_log_path
643649
]
644650

645651
if Util.os == :windows
@@ -649,7 +655,7 @@ def initialize(ports)
649655
args = [Paths.mix_release_boot_path] + args
650656
end
651657

652-
super(cmd, args, Paths.tau_log_path)
658+
super(cmd, args, nil)
653659
end
654660

655661
def process_running?

0 commit comments

Comments
 (0)