spacewander commented on a change in pull request #5682:
URL: https://github.com/apache/apisix/pull/5682#discussion_r762510887



##########
File path: apisix/patch.lua
##########
@@ -86,6 +92,53 @@ do
 end
 
 
+-- Inspired by kong.globalpatches
+do -- `_G.math.randomseed` patch
+    local resty_random = require("resty.random")
+    local math_randomseed = math.randomseed
+    local seeded = {}
+    -- make linter happy
+    -- luacheck: ignore
+    _G.math.randomseed = function()
+        local seed
+        local worker_pid = ngx.worker.pid()
+
+        -- check seed mark
+        if seeded[worker_pid] then
+            log(WARN, debug.traceback("attempt to seed already seeded random 
number " ..

Review comment:
       Let's use DEBUG level log like what kong has done.

##########
File path: apisix/patch.lua
##########
@@ -86,6 +92,53 @@ do
 end
 
 
+-- Inspired by kong.globalpatches
+do -- `_G.math.randomseed` patch
+    local resty_random = require("resty.random")
+    local math_randomseed = math.randomseed
+    local seeded = {}
+    -- make linter happy
+    -- luacheck: ignore
+    _G.math.randomseed = function()
+        local seed
+        local worker_pid = ngx.worker.pid()
+
+        -- check seed mark
+        if seeded[worker_pid] then
+            log(WARN, debug.traceback("attempt to seed already seeded random 
number " ..
+                                      "generator on process #" .. 
tostring(worker_pid), 2))
+            return
+        end
+
+        -- get randomseed
+        local bytes = resty_random.bytes(8)
+        if bytes then
+            log(ngx.INFO, "seeding from resty.random.bytes")
+
+            local t = {}
+            for i = 1, #bytes do

Review comment:
       We can check if `#str > 12` here. And we need to comment why 12 is 
chosen.

##########
File path: apisix/patch.lua
##########
@@ -86,6 +92,53 @@ do
 end
 
 
+-- Inspired by kong.globalpatches
+do -- `_G.math.randomseed` patch
+    local resty_random = require("resty.random")
+    local math_randomseed = math.randomseed
+    local seeded = {}
+    -- make linter happy
+    -- luacheck: ignore
+    _G.math.randomseed = function()
+        local seed
+        local worker_pid = ngx.worker.pid()
+
+        -- check seed mark
+        if seeded[worker_pid] then
+            log(WARN, debug.traceback("attempt to seed already seeded random 
number " ..
+                                      "generator on process #" .. 
tostring(worker_pid), 2))
+            return
+        end
+
+        -- get randomseed
+        local bytes = resty_random.bytes(8)
+        if bytes then
+            log(ngx.INFO, "seeding from resty.random.bytes")

Review comment:
       Ditto




-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to