Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[backport -> release/3.6.x] chore(wasm): reuse kong.dns object for DNS bridge #12652

Closed

Conversation

team-gateway-bot
Copy link
Collaborator

Automated backport to release/3.6.x, triggered by a label in #12465.

Original description

The overall goal of this PR is to make the Wasm subsystem a better citizen of Kong.

Summary

The original code used the kong.tools.dns module to attempt* to instantiate its own DNS client:

kong/kong/runloop/wasm.lua

Lines 838 to 839 in b7d50b0

-- setup a DNS client for ngx_wasm_module
_G.dns_client = _G.dns_client or dns(kong_config)

This has not caused any problems that we are aware of, but it's not the correct behavior and could potentially lead to problems further down the line with the DNS client rewrite looming.

Reusing the global kong.dns object necessitates moving this initialization code to the init_worker phase to work around some order-of-operations challenges (wasm.init() needs to run before core entity schemas are loaded, which is also before kong.dns is initialized).

Additionally, I have added some checks around our special ngx.IS_CLI flag to avoid setup steps in CLI mode. This means that test code that uses kong.runloop.wasm will not be expected to mock global objects that are effectively unused in this context.

*the DNS client code uses a singleton pattern with state kept at the module level, so it does not in fact create a "new" DNS client--it merely re-configures the existing one in-place.

Checklist

  • The Pull Request has tests (there are existing tests for DNS queries within Wasm filters)
  • A changelog file has been created under changelog/unreleased/kong or skip-changelog label added on PR if changelog is unnecessary. README.md
  • There is a user-facing docs PR against https://github.com/Kong/docs.konghq.com

Issue reference

KAG-3644

The original code was attempting to instantiate its own DNS client,
which is really not possible given the singleton nature of the module.
The correct and more maintainable behavior here is to explicitly reuse
the global client instance at `kong.dns`.

(cherry picked from commit 70ac29d)
@team-gateway-bot team-gateway-bot added cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee core/proxy core/wasm Everything relevant to [proxy-]wasm size/S skip-changelog labels Feb 27, 2024
@flrgh flrgh closed this Feb 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick kong-ee schedule this PR for cherry-picking to kong/kong-ee core/proxy core/wasm Everything relevant to [proxy-]wasm size/S skip-changelog
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants