Skip to content

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
beefproject:masterfrom
qianeric-backup:fix/dns-console-logger
Open

qianeric-backup wants to merge 1 commit into
beefproject:masterfrom
qianeric-backup:fix/dns-console-logger

Conversation

@qianeric-backup

Copy link
Copy Markdown

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.

def initialize
  super()
  logger.level = Logger::ERROR      # NoMethodError: undefined method 'level=' for module Console

logger inside Async::DNS::Server is a deprecated shim that returns the Console module rather than a logger instance:

# @deprecated Use {Console} instead.
def logger
  Console
end

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 Console instead:

         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::ERROR

A 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 in Gemfile.lock (async-dns 1.4.1, console 1.34.0):

  • async-dns-1.4.1/lib/async/dns/server.rb — #logger returns Console; Console exposes no level=, which is the reported NoMethodError.
  • console-1.34.0/lib/console/interface.rb — Console.logger returns Interface.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], so Console::Logger::ERROR exists and is 3.
  • console-1.34.0/lib/console/filter.rb — def level=(level) accepts a Symbol or an Integer, so both Console::Logger::ERROR and :error would work; I used the constant to keep the original intent explicit.

Console is already reachable at this point because Async::DNS::Server loads it transitively, so no new require is needed.

Scope: Bug 2 is not addressed here

#3680 also reports that the nameserver never binds, because run still starts super() from EventMachine.next_tick plus a bare Thread.new, and stop calls EventMachine.stop. Async::DNS::Server#run needs an Async reactor, so that is a structural change: run the server inside an Async { ... } block on its own thread, pass the configured endpoint through instead of relying on default_endpoint, and shut the reactor down in stop. 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.

… 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

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant