Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

request:go timeout doesn't work? #172

Open
zhiburt opened this issue Sep 18, 2020 · 0 comments
Open

request:go timeout doesn't work? #172

zhiburt opened this issue Sep 18, 2020 · 0 comments

Comments

@zhiburt
Copy link

zhiburt commented Sep 18, 2020

Issue

I was experimenting with Lua and follow your examples from documentation.
And I've noticed that timeout on go function seems don't work from time to time...
It works for certain cases but sometimes its not.

I had a simple script which does 5-10 request in a loop. And I've noticed that most of time it stuck on forever waiting of go method.
The behavior is reproducible (I guess).

One strange thing happening when it stucks in most cases I got opened a page in firefox. (That's why I was thinking about redirecting here)

I do provide here an output of trace which I get after Ctrl+C. I do not provide an exact script and data since it seems to be unnecessary. (In the best case scenario every one can bump into this by creating a loop for 5-10 request. In the worst one it's a tricky issue. And most likely I am doing something wrong).

I am not sure if the issue is worth being overseeing. But I decided create an issue since I did spend a couple of hours haven't found any explanation for that behavior so far.

A basis of the script I use

for _, url in ipairs(urls) do
    req(url)
end

function req(url)
    local req = http_request.new_from_uri(url)
    req.follow_redirects = false

    local headers, stream = req:go(5)
    if headers == nil then
        return nil
    end
    if headers:get ":status" ~= "200" then
        return nil
    end

    local body = assert(stream:get_body_as_string())
    return body
end

most often traces

lua: /usr/share/lua/5.4/http/h2_connection.lua:253: interrupted!
stack traceback:
	/usr/share/lua/5.4/http/h2_connection.lua:372: in method 'read_http2_frame'
	/usr/share/lua/5.4/http/h2_connection.lua:253: in method 'step'
	/usr/share/lua/5.4/http/h2_stream.lua:1221: in method 'get_headers'
	/usr/share/lua/5.4/http/request.lua:592: in method 'go'
	main.lua:18: in local 'request'
	main.lua:42: in main chunk
	[C]: in ?
lua: /usr/share/lua/5.4/cqueues/socket.lua:103: interrupted!
stack traceback:
	[C]: in upvalue '_onerror'
	/usr/share/lua/5.4/cqueues/socket.lua:103: in method 'onerror'
	/usr/share/lua/5.4/cqueues/socket.lua:138: in upvalue 'oops'
	/usr/share/lua/5.4/cqueues/socket.lua:555: in method 'xread'
	/usr/share/lua/5.4/http/h2_connection.lua:361: in method 'read_http2_frame'
	/usr/share/lua/5.4/http/h2_connection.lua:253: in method 'step'
	/usr/share/lua/5.4/http/h2_stream.lua:1221: in method 'get_headers'
	/usr/share/lua/5.4/http/request.lua:592: in method 'go'
	main.lua:18: in local 'request'
	main.lua:42: in main chunk

too much CPU consumption?

Waiting consumes a lot of CPU

image

Thank you for the library.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant