You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
attempt to yield across C-call boundary in function 'require' with Openresty #78
2017/07/06 12:37:19 [error] 14#14: *1 lua entry thread aborted: runtime error: attempt to yield across C-call boundary
stack traceback:
coroutine 0:
[C]: in function 'require'
/var/www/config/nginx/lua/google_pubsub.lua:8: in function </var/www/config/nginx/lua/google_pubsub.lua:1>,
I'm using lua-http to sent push (POST) requests to Google Pub/Sub with function like this:
local http_request = require("http.request")
local http_headers = require("http.headers")
local req2 = function(uri, body, auth)
local headers = http_headers.new()
headers:append(":authorization", auth)
headers:append(":content-length", #body)
local request = http_request.new_from_uri(uri)
request.version = 2
request.tls = true
request.port = 443
request.headers = headers
request:set_body(body)
local resp_headers, stream = request:go()
if resp_headers:get ":status" ~= "200" then
ngx.log(ngx.ERR, stream:get_body_as_string())
end
end
Also, here's a Dockerfile snippet with deps installing process:
FROM openresty/openresty:alpine
RUN \
apk update && \
apk add --no-cache unzip gcc make linux-headers bsd-compat-headers musl-dev m4
RUN \
apk add --no-cache openssl openssl-dev lua5.1 lua5.1-dev luajit luarocks5.1 lua5.1-cjson lua5.1-socket lua5.1-sec lua5.1-crypto lua5.1-lpeg
RUN \
luarocks-5.1 install http && \
ln -s /usr/local/share/lua/5.1/http_0_2_0-http/ /usr/local/share/lua/5.1/http
I'm using lua-http to sent push (POST) requests to Google Pub/Sub with function like this:
Note that cqueues (and hence lua-http) doesn't currently play nice with openresty: :go() and other lua-http blocking operations will block the nginx main loop. This is something I've tried to fix before ( see openresty/lua-nginx-module#450)
I'm using lua-http to sent push (POST) requests to Google Pub/Sub with function like this:
...
Also, here's a Dockerfile snippet with deps installing process:
What do I do with these? Could you give me complete instructions to replicate?
What do I do with these? Could you give me complete instructions to replicate?
I thought, maybe some packages have wrong versions or are missing.
It's odd that you need this....
Yup, but that's the way luarocks install this module in the alpine linux.
will block the nginx main loop
So, it's a bad idea for me to use Openresty for this purpose, or bare-metal Nginx with some special modules should do the trick? (sorry for a newbie question) Maybe, I should give some other web server a spin in that case?
What do I do with these? Could you give me complete instructions to replicate?
I thought, maybe some packages have wrong versions or are missing.
I mean: can you give me a sequence of commands to type into my shell to make that docker snippet + lua snippet throw the error? i.e. give me the full docker file; give me a full nginx.conf; etc.
It takes me far longer if I have to read through how the docker image you use is created+how it's meant to be configured, and then code up 100 lines of supporting config+code just to make your snippet run.
Yup, but that's the way luarocks install this module in the alpine linux.
Has this been brought up with the alpine luarocks maintainer? @jirutka ping.
So, it's a bad idea for me to use Openresty for this purpose,
It won't be performant if you use the default lua-http blocking API.
One solution is to not use any blocking APIs. i.e. you'd need to call things with a timeout of 0. This mode of use isn't fully fleshed out in the current lua-http release (e.g. there's no request-in-progress object (see https://github.com/daurnimator/lua-http/projects/2#card-552050)); but you should be able to get something basic working.
bare-metal Nginx with some special modules should do the trick
I'm not sure if there is a nginx http2 client module that supports this type of usage.
Maybe, I should give some other web server a spin in that case?
It errors with attempt to index a nil value (field 'headers') if I try to add headers to an existing one.
Won't you, please, review my code? I'm a complete newbie in Lua and not a programmer at all, so only with a little help from my friends I can get something working.
The error happens because of the timeout. On timeout the go method returns nil, the error message and error number so your resp_headers variable gets the value nil. I'd say that there's something wrong with the headers. The possible errors are described here (section 3.1.3) if you're interested. Have you tried doing the same request with some other tool like curl?
Activity
daurnimator commentedon Jul 6, 2017
Could you give me a traceback? I'm curious where this is coming from.
Blasterdick commentedon Jul 6, 2017
I'm using
lua-httpto sent push (POST) requests to Google Pub/Sub with function like this:Also, here's a Dockerfile snippet with deps installing process:
Here's nginx.conf snippet of
lua_package_path:daurnimator commentedon Jul 7, 2017
Note that cqueues (and hence lua-http) doesn't currently play nice with openresty:
:go()and other lua-http blocking operations will block the nginx main loop. This is something I've tried to fix before ( see openresty/lua-nginx-module#450)What do I do with these? Could you give me complete instructions to replicate?
It's odd that you need this....
Blasterdick commentedon Jul 7, 2017
I thought, maybe some packages have wrong versions or are missing.
Yup, but that's the way luarocks install this module in the alpine linux.
So, it's a bad idea for me to use Openresty for this purpose, or bare-metal Nginx with some special modules should do the trick? (sorry for a newbie question) Maybe, I should give some other web server a spin in that case?
daurnimator commentedon Jul 8, 2017
I mean: can you give me a sequence of commands to type into my shell to make that docker snippet + lua snippet throw the error? i.e. give me the full docker file; give me a full nginx.conf; etc.
It takes me far longer if I have to read through how the docker image you use is created+how it's meant to be configured, and then code up 100 lines of supporting config+code just to make your snippet run.
Has this been brought up with the alpine luarocks maintainer? @jirutka ping.
It won't be performant if you use the default lua-http blocking API.
One solution is to not use any blocking APIs. i.e. you'd need to call things with a timeout of
0. This mode of use isn't fully fleshed out in the current lua-http release (e.g. there's no request-in-progress object (see https://github.com/daurnimator/lua-http/projects/2#card-552050)); but you should be able to get something basic working.I'm not sure if there is a nginx http2 client module that supports this type of usage.
Maybe. I don't fully know what you're trying to do.
You could use lua-http to create a minimal http server (see https://github.com/daurnimator/lua-http/blob/master/examples/server_hello.lua) and then use it as an upstream from your nginx instance.
Blasterdick commentedon Jul 12, 2017
Thank you for a suggestion, now I'm trying to use
http-luaas a server, and I'm getting this error:Pseudo-header fields are only valid in the context in which they are definedwith next code:
daurnimator commentedon Jul 12, 2017
":authorization"and":content-length"are not a valid pseudo headers (you probably didn't mean to write the colon).The only headers that can start with
:are :path, :method, :authority, :scheme and :status. See http://httpwg.org/specs/rfc7540.html#PseudoHeaderFields for more info.Avoid replacing the headers field: instead modify the existing one.
If you do so, you can avoid upserting scheme and path.
Blasterdick commentedon Jul 13, 2017
It errors with
attempt to index a nil value (field 'headers')if I try to add headers to an existing one.Won't you, please, review my code? I'm a complete newbie in Lua and not a programmer at all, so only with a little help from my friends I can get something working.
Thanks in advance. comrade.
Blasterdick commentedon Jul 13, 2017
After some editing, I came up with this version.
Now it hangs till timeout and errors with:
failed: pubsub_push.lua:17: attempt to index a nil value (local 'resp_headers')While
netstatshows an open connection to Google PubSub IP from appropriate PID.rokf commentedon Jul 19, 2017
The error happens because of the timeout. On timeout the
gomethod returnsnil, the error message and error number so yourresp_headersvariable gets the valuenil. I'd say that there's something wrong with the headers. The possible errors are described here (section 3.1.3) if you're interested. Have you tried doing the same request with some other tool likecurl?Blasterdick commentedon Jul 19, 2017
Thanks for a suggestion, comrade. Yup, I've tried with Postman with the same headers and raw POST data.
Duplicated question here.
rokf commentedon Jul 19, 2017
Does your request body have the correct
JSONformat like required?(https://cloud.google.com/pubsub/docs/reference/rest/v1/projects.topics/publish)Blasterdick commentedon Jul 19, 2017
Affirmative. With Postman everything works as expected.
daurnimator commentedon Jul 24, 2017
I was able to make your code work.
Notes:
"*l"to read your token so you know you don't get a newlineassertwith most lua-http calls (or handle your errors):get_body_as_string():go()io.opendaurnimator commentedon Jul 26, 2017
@Blasterdick okay to close?
Blasterdick commentedon Jul 27, 2017
@daurnimator For now I'm using the code, adapted for my needs from this article.
Thank you anyway, I'll try to modify my Lua code, and would give it a spin as well.