Repository navigation
fix(dns): set the log level on the Console logger, not on the Console module - #3688
Open
qianeric-backup wants to merge 1 commit into
Open
qianeric-backup wants to merge 1 commit into
qianeric-backup wants to merge 1 commit into
Conversation
… module
Server#initialize called `logger.level = Logger::ERROR`. `logger` here is
Async::DNS::Server#logger, which is a deprecated shim that returns the
Console module itself:
# @deprecated Use {Console} instead.
def logger
Console
end
The Console module has no `level=` method, so constructing the singleton
raised `NoMethodError: undefined method 'level=' for module Console`. The
REST layer builds that singleton in a `before` filter, so every
`/api/dns/*` request answered 500 and the extension was unusable.
The logger instance that does accept a level is the one behind
`Console.logger`:
- `Console.logger` returns the current logger (Console::Interface), a
Console::Logger instance.
- Console::Logger is built as `Filter[debug: 0, info: 1, warn: 2,
error: 3, fatal: 4]`, so `Console::Logger::ERROR` resolves to 3.
- Filter defines `level=`, accepting either a Symbol or an Integer.
No behaviour changes beyond the logging call: the level is still ERROR, it
is just applied to an object that has the writer.
I could not execute the extension here (no Ruby toolchain in my
environment), so this is verified against the sources of the locked
versions rather than at run time: async-dns 1.4.1 for #logger and console
1.34.0 for the logger/level API, both as pinned in Gemfile.lock.
This addresses Bug 1 of beefproject#3680 only. Bug 2 (the nameserver never binding,
because run/stop still assume an EventMachine reactor) is a structural
change that needs an Async reactor and a way to exercise it, and I would
rather not bundle it with a one-line fix.
Refs beefproject#3680
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Category
Bug
Feature/Issue Description
Q: Please give a brief summary of your feature/fix
A:
Fixes Bug 1 of #3680: building the DNS extension's server singleton raised
NoMethodError, which made every/api/dns/*request answer 500.loggerinsideAsync::DNS::Serveris a deprecated shim that returns theConsolemodule rather than a logger instance:The module is not where
level=lives.Q: Give a technical rundown of what you have changed (if applicable)
A:
Applied the level to the logger instance behind
Consoleinstead:def initialize super() - logger.level = Logger::ERROR + # Async::DNS::Server#logger returns the Console module itself, which + # has no level= method. The per-instance logger behind Console is the + # one that accepts a level. + Console.logger.level = Console::Logger::ERRORA one-line change, no behaviour change beyond the call: the level is still
ERROR, it is just applied to an object that actually defines the writer.Test Cases
Q: Describe your test cases, what you have covered and if there are any use cases that still need addressing.
A:
I have no Ruby toolchain in my environment, so I could not start BeEF and hit
/api/dns/*. Instead I verified the whole chain against the sources of the versions pinned inGemfile.lock(async-dns 1.4.1,console 1.34.0):async-dns-1.4.1/lib/async/dns/server.rb—#loggerreturnsConsole;Consoleexposes nolevel=, which is the reportedNoMethodError.console-1.34.0/lib/console/interface.rb—Console.loggerreturnsInterface.instance, the actual logger.console-1.34.0/lib/console/logger.rb—class Logger < Filter[debug: 0, info: 1, warn: 2, error: 3, fatal: 4], soConsole::Logger::ERRORexists and is3.console-1.34.0/lib/console/filter.rb—def level=(level)accepts a Symbol or an Integer, so bothConsole::Logger::ERRORand:errorwould work; I used the constant to keep the original intent explicit.Consoleis already reachable at this point becauseAsync::DNS::Serverloads it transitively, so no newrequireis needed.Scope: Bug 2 is not addressed here
#3680 also reports that the nameserver never binds, because
runstill startssuper()fromEventMachine.next_tickplus a bareThread.new, andstopcallsEventMachine.stop.Async::DNS::Server#runneeds an Async reactor, so that is a structural change: run the server inside anAsync { ... }block on its own thread, pass the configured endpoint through instead of relying ondefault_endpoint, and shut the reactor down instop. I would rather not fold that into a one-line fix, and I have no way to exercise a reactor change in this environment. Happy to follow up with a separate PR for Bug 2, or to add it here if you would prefer one change.With Bug 1 fixed,
/api/dns/*should stop returning 500 and the extension's rule management should be reachable again, but resolving queries will still not work until Bug 2 is done.Refs #3680
Wiki Page
Not applicable; this restores the documented behaviour of an existing extension rather than adding anything new.