Improve error handling in hijacked code
This commit is contained in:
parent
7f2eeaf767
commit
6c82a50903
|
@ -442,6 +442,25 @@ module Discourse
|
|||
nil
|
||||
end
|
||||
|
||||
# report a warning maintaining backtrack for logster
|
||||
def self.warn_exception(e, message: "", env: nil)
|
||||
if Rails.logger.respond_to? :add_with_opts
|
||||
# logster
|
||||
Rails.logger.add_with_opts(
|
||||
::Logger::Severity::WARN,
|
||||
"#{message} : #{e}",
|
||||
"discourse-exception",
|
||||
backtrace: e.backtrace.join("\n"),
|
||||
env: env
|
||||
)
|
||||
else
|
||||
# no logster ... fallback
|
||||
Rails.logger.warn("#{message} #{e}")
|
||||
end
|
||||
rescue
|
||||
STDERR.puts "Failed to report exception #{e} #{message}"
|
||||
end
|
||||
|
||||
def self.start_connection_reaper
|
||||
return if GlobalSetting.connection_reaper_age < 1 ||
|
||||
GlobalSetting.connection_reaper_interval < 1
|
||||
|
@ -453,7 +472,7 @@ module Discourse
|
|||
sleep GlobalSetting.connection_reaper_interval
|
||||
reap_connections(GlobalSetting.connection_reaper_age, GlobalSetting.connection_reaper_max_age)
|
||||
rescue => e
|
||||
Discourse.handle_exception(e, message: "Error reaping connections")
|
||||
Discourse.warn_exception(e, message: "Error reaping connections")
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -26,6 +26,7 @@ module Hijack
|
|||
MethodProfiler.start(transfer_timings) if defined? MethodProfiler
|
||||
|
||||
begin
|
||||
Thread.current[Logster::Logger::LOGSTER_ENV] = env_copy
|
||||
# do this first to confirm we have a working connection
|
||||
# before doing any work
|
||||
io.write "HTTP/1.1 "
|
||||
|
@ -41,7 +42,8 @@ module Hijack
|
|||
begin
|
||||
instance.instance_eval(&blk)
|
||||
rescue => e
|
||||
Rails.logger.warn("Failed to process hijacked response correctly #{e}")
|
||||
# TODO we need to reuse our exception handling in ApplicationController
|
||||
Discourse.warn_exception(e, message: "Failed to process hijacked response correctly", env: env_copy)
|
||||
end
|
||||
|
||||
unless instance.response_body || response.committed?
|
||||
|
@ -71,6 +73,8 @@ module Hijack
|
|||
io = nil
|
||||
ensure
|
||||
|
||||
Thread.current[Logster::Logger::LOGSTER_ENV] = nil
|
||||
|
||||
io.close if io rescue nil
|
||||
|
||||
if request_tracker
|
||||
|
|
Loading…
Reference in New Issue