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

fix(core): use require implementation written in Lua #11610

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions CHANGELOG/unreleased/kong/11610.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
"message": "Use `require` implementation written in Lua to enable cosocket calls on the module level of libraries"
"type": "feature"
"scope": "Core"
"prs":
- 11610
jiras:
- "KAG-2595"
8 changes: 0 additions & 8 deletions bin/busted
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,6 @@ require("kong.globalpatches")({
rbusted = true
})

-- some libraries used in test like spec/helpers
-- calls cosocket in module level, and as LuaJIT's
-- `require` is implemented in C, this throws
-- "attempt to yield across C-call boundary" error
-- the following pure-lua implementation is to bypass
-- this limitation, without need to modify all tests
_G.require = require "spec.require".require

-- Busted command-line runner
require 'busted.runner'({ standalone = false })

Expand Down
1 change: 1 addition & 0 deletions kong-3.5.0-0.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,7 @@ build = {
["kong.tools.stream_api"] = "kong/tools/stream_api.lua",
["kong.tools.queue"] = "kong/tools/queue.lua",
["kong.tools.queue_schema"] = "kong/tools/queue_schema.lua",
["kong.tools.require"] = "kong/tools/require.lua",
["kong.tools.sandbox"] = "kong/tools/sandbox.lua",
["kong.tools.uri"] = "kong/tools/uri.lua",
["kong.tools.kong-lua-sandbox"] = "kong/tools/kong-lua-sandbox.lua",
Expand Down
8 changes: 8 additions & 0 deletions kong/globalpatches.lua
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,14 @@ return function(options)
return sock
end

-- Some libraries call cosocket on the module level, and as
-- LuaJIT's `require` is implemented in C, this throws "attempt to
-- yield across C-call boundary" error. We're replacing require
-- with an implementation written in Lua that does not have the
-- restriction.
_G.native_require = require
_G.require = require "kong.tools.require".require
hanshuebner marked this conversation as resolved.
Show resolved Hide resolved

-- STEP 5: load code that should be using the patched versions, if any (because of dependency chain)
do
local client = package.loaded["kong.resty.dns.client"]
Expand Down
File renamed without changes.