luvit / lit

Toolkit for developing, sharing, and running luvit/lua programs and libraries.
http://lit.luvit.io/
Apache License 2.0
245 stars 58 forks source link

Handle timeout requests #270

Closed Lautenschlager-id closed 4 years ago

Lautenschlager-id commented 4 years ago

When you set a timeout value in coro-http.request, it can happen that the returned value for write is a string "timeout", and it ends up breaking in write(req).

Now, it returns a nil header with body "timeout".

Refers to

Uncaught Error: .../deps/coro-http.lua:137: attempt to call local 'write' (a string value)

May be helpful for https://github.com/luvit/lit/issues/216

SinisterRectus commented 4 years ago

216 should have been closed with #223.

Does this always happen? Can you provide code to reproduce the issue?

Lautenschlager-id commented 4 years ago

Yes, I saw your PR but unfortunately it does not handle connection.write when it is string.

You can reproduce it with the code provided in #216

local http = require("coro-http")
coroutine.wrap(function()
  http.request("GET", "http://123.123.123.123/", nil, nil, 1000) -- Sets the timeout to 1s
end)()
SinisterRectus commented 4 years ago

I don't get your error. I get:

C:\Users\Sinister\Desktop>luvit test.lua
Uncaught Error: C:/Users/Sinister/Desktop/deps/coro-http.lua:74: timeout
stack traceback:
        [builtin#2]: at 0x7ff7df1e9eb0
        [C]: in function 'run'
        [string "bundle:/init.lua"]:52: in function <[string "bundle:/init.lua"]:47>
        [C]: in function 'xpcall'
        [string "bundle:/init.lua"]:47: in function 'fn'
        [string "bundle:deps/require.lua"]:310: in function <[string "bundle:deps/require.lua"]:266>
Lautenschlager-id commented 4 years ago

Oh, I see getConnection uses assert now :thinking:

When did that happen? I have been using a pretty recent version and git blame says it is there for 4 yearslol

SinisterRectus commented 4 years ago

Not sure. I do know that there is a discrepancy between coro-http (which uses assert) and coro-websocket (which returns nil, err).