Skip to content

bug: serverless is executing the pre and post function but not calling the upstream api #4923

@pawarJayesh8511

Description

@pawarJayesh8511

Issue description

I have following route defined

{
"key":"/apisix/routes/154",
"createdIndex":1134,
"modifiedIndex":1136,
"value":{
"upstream":{
"nodes":{
"xxx.xxx.xxx.1:9282":1
},
"type":"roundrobin",
"hash_on":"vars",
"scheme":"http",
"pass_host":"pass"
},
"priority":0,
"id":"154",
"update_time":1630033424,
"uri":"/api/serverless",
"status":1,
"create_time":1630033217,
"plugins":{
"serverless-pre-function":{
"functions":[
"local count = 1 return function() count = count + 1 ngx.say(count) end"
],
"phase":"access"
}
}
}
}

Output:
curl -i http://127.0.0.1:9080/api/serverless
HTTP/1.1 200 OK
Date: Sun, 29 Aug 2021 14:59:57 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.8

2

Environment

  • apisix version (cmd: apisix version):
  • OS (cmd: uname -a):
  • OpenResty / Nginx version (cmd: nginx -V or openresty -V):
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • luarocks version, if the issue is about installation (cmd: luarocks --version):

Steps to reproduce

I have following route defined step in https://apisix.apache.org/docs/apisix/plugins/serverless
Route is as follows:

{
"key":"/apisix/routes/154",
"createdIndex":1134,
"modifiedIndex":1136,
"value":{
"upstream":{
"nodes":{
"xxx.xxx.xxx.1:9282":1
},
"type":"roundrobin",
"hash_on":"vars",
"scheme":"http",
"pass_host":"pass"
},
"priority":0,
"id":"154",
"update_time":1630033424,
"uri":"/api/serverless",
"status":1,
"create_time":1630033217,
"plugins":{
"serverless-pre-function":{
"functions":[
"local count = 1 return function() count = count + 1 ngx.say(count) end"
],
"phase":"access"
}
}
}
}

Actual result

curl -i http://127.0.0.1:9080/api/serverless

Output:

HTTP/1.1 200 OK
Date: Sun, 29 Aug 2021 14:59:57 GMT
Content-Type: text/plain; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX/2.8

2

Error log

Please note, we don't have anything for in error.log file when we execute the "phase":"access"

But, when I tried with "phase":"log", I am getting the following error.
2021/08/29 20:27:52 [error] 6062#6062: 159428 failed to run log_by_lua: [string "local count = 1 return function() count = cou..."]:1: API disabled in the context of log_by_lua*
stack traceback:
[C]: in function 'say'
[string "local count = 1 return function() count = cou..."]:1: in function 'func'
...apisix-2.8/apisix-2.8/apisix/plugins/serverless/init.lua:78: in function 'call_funcs'
...apisix-2.8/apisix-2.8/apisix/plugins/serverless/init.lua:129: in function 'phase_func'
...six/installation/apisix-2.8/apisix-2.8/apisix/plugin.lua:679: in function 'common_phase'
...pisix/installation/apisix-2.8/apisix-2.8/apisix/init.lua:681: in function 'http_log_phase'
log_by_lua(nginx.conf:279):2: in main chunk while logging request, client: 127.0.0.1, server: _, request: "GET /api/serverless HTTP/1.1", upstream: "http://192.168.56.1:9282/api/serverless", host: "127.0.0.1:9080"

Expected result

Pre and post function should get called and also upstream actual end point should get called.

curl -i http://127.0.0.1:9080/api/serverless
2 called the actual upstream endpoint for serverless

This is not happening

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions