This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 30378f5a6 fix: ensure the core.grpc is nil under vanilla OpenResty 
(#8007)
30378f5a6 is described below

commit 30378f5a64eb41446831b54b6c8ec042e004e098
Author: 罗泽轩 <[email protected]>
AuthorDate: Thu Sep 29 13:56:36 2022 +0800

    fix: ensure the core.grpc is nil under vanilla OpenResty (#8007)
---
 apisix/init.lua         |  4 ++++
 t/core/grpc-openresty.t | 54 +++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/apisix/init.lua b/apisix/init.lua
index b2e0b706b..3100cc1d2 100644
--- a/apisix/init.lua
+++ b/apisix/init.lua
@@ -55,6 +55,7 @@ local re_split        = require("ngx.re").split
 local str_byte        = string.byte
 local str_sub         = string.sub
 local tonumber        = tonumber
+local type            = type
 local pairs           = pairs
 local control_api_router
 
@@ -112,6 +113,9 @@ function _M.http_init_worker()
     -- Because go's scheduler doesn't work after fork, we have to load the 
gRPC module
     -- in each worker.
     core.grpc = require("apisix.core.grpc")
+    if type(core.grpc) ~= "table" then
+        core.grpc = nil
+    end
 
     local we = require("resty.worker.events")
     local ok, err = we.configure({shm = "worker-events", interval = 0.1})
diff --git a/t/core/grpc-openresty.t b/t/core/grpc-openresty.t
new file mode 100644
index 000000000..30772f23e
--- /dev/null
+++ b/t/core/grpc-openresty.t
@@ -0,0 +1,54 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+#
+use t::APISIX;
+
+my $nginx_binary = $ENV{'TEST_NGINX_BINARY'} || 'nginx';
+my $version = eval { `$nginx_binary -V 2>&1` };
+
+if ($version =~ m/\/apisix-nginx-module/) {
+    plan(skip_all => "for vanilla OpenResty only");
+} else {
+    plan('no_plan');
+}
+
+add_block_preprocessor(sub {
+    my ($block) = @_;
+
+    if (!$block->request) {
+        $block->set_value("request", "GET /t");
+    }
+
+    if ((!defined $block->error_log) && (!defined $block->no_error_log)) {
+        $block->set_value("no_error_log", "[error]");
+    }
+});
+
+run_tests;
+
+__DATA__
+
+=== TEST 1: ensure the core.grpc is nil under vanilla OpenResty
+--- config
+    location /t {
+        content_by_lua_block {
+            local core = require "apisix.core"
+            local gcli = core.grpc
+            ngx.say(gcli)
+        }
+    }
+--- response_body
+nil

Reply via email to