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

coro-http has no timeout #216

Open edubart opened 7 years ago

edubart commented 7 years ago

Coro http has no timeout option, if you do a HTTP request to an unresponsive address the coroutine it will never resume.

Test case:

local http = require 'coro-http'
coroutine.wrap(function()
  http.request('GET', 'http://123.123.123.123/')
end)()

Running this example with luvit it will run forever.

This is problematic because I was running a daemon using coro-http and it got stuck forever when my network was down, even after the network became alive again.

halfnelson commented 7 years ago

I hit the same problem and I made some changes to my copy of the the core coro-wrapper and coro-channel libraries to provide support for optional read timeouts. They would need to be wired through to http library, but shouldn't be too difficult. Just look for :read in there.

creationix commented 7 years ago

@halfnelson would you like to send a PR to see if your changes can get merged here?