apache / openwhisk-apigateway

Apache OpenWhisk API Gateway service for exposing actions as REST interfaces.
https://openwhisk.apache.org/
Apache License 2.0
64 stars 45 forks source link

error: Unable to create API: API creation failure: Unable to configure the API Gateway (status code 500): #376

Closed jiangpengcheng closed 4 years ago

jiangpengcheng commented 4 years ago

Error

can not create api

Step to reproduce

  1. create an api:
wsk -i api create /root /path get hello
  1. get the api url and invoke it
# ~ wsk -i api list
ok: APIs
Action                 Verb  API Name  URL
/whisk.system/hello     get     /root  http://172.17.0.1:9001/api/789c46b1-71f6-4ed5-8c54-816aa4f8c502/root/path

# ~ curl http://172.17.0.1:9001/api/789c46b1-71f6-4ed5-8c54-816aa4f8c502/root/path
{

}
  1. then create a second api, this will be failed
# ~ wsk -i api create /root /path2 get hello
error: Unable to create API: API creation failure: Unable to configure the API Gateway (status code 500): "<html>\r\n<head><title>500 Internal Server Error</title></head>\r\n<body>\r\n<center><h1>500 Internal Server Error</h1></center>\r\n<hr><center>openresty/1.15.8.3</center>\r\n</body>\r\n</html>\r\n"

Reason

the apigateway container complains about an error:

==> /var/log/api-gateway/management.log <==
2020/07/01 03:15:21 [error] 56#0: *65 lua entry thread aborted: runtime error: /etc/api-gateway/scripts/lua/routing.lua:250: bad argument #1 to 'pairs' (table expected, got nil)
stack traceback:
coroutine 0:
    [C]: in function 'pairs'
    /etc/api-gateway/scripts/lua/routing.lua:250: in function 'parsePolicies'
    /etc/api-gateway/scripts/lua/management/lib/swagger.lua:28: in function 'parseSwagger'
    /etc/api-gateway/scripts/lua/management/routes/apis.lua:123: in function 'addAPI'
    /etc/api-gateway/scripts/lua/management/routes/apis.lua:43: in function 'requestHandler'
    access_by_lua(management_apis.conf:36):5: in main chunk, client: 172.17.0.1, server: management_gw, request: "PUT /v2/789c46b1-71f6-4ed5-8c54-816aa4f8c502/apis/5bba0e4c-c700-4c32-ba57-1e857584e9d9 HTTP/1.1", host: "172.17.0.1:9000"

and after look through codes and debugging, it seems that in second and subsequent api creation, the method scripts/lua/management/lib/swagger.lua#parseSwagger which should call method scripts/lua/management/lib/swagger.lua#parsePolicies but actually it's called scripts/lua/routing.lua#parsePolicies

and this error also lead to some system tests failed:

jiangpengcheng commented 4 years ago

although I didn't know the real reason why there is conflict, but seems it is imported by openrestry upgrade: #374