0

I'm doing a long poll request setting a timeout of 10 sec but it does not seem to be working. My understanding is if we don't get a response from backend within the specified timeout, backend call should end with timedout error code. Is it so?

But if I use a very small timeout e.g. 0.001, it works. So I think if a request is already sent to backend, timeout does not work.

For my long poll request, if my network is down when a request is sent and waiting for response, lua socket hangs there and it never recovers from that situation. Could you please help me if I can handle this in any other way?

My Lua version - Lua 5.1.4 Copyright (C) 1994-2008 Lua.org, PUC-Rio (double int32)

Code Spinet:

local http = require "socket.http"
local https = require "ssl.https"
http.TIMEOUT = 10
local r,s,h = https.request({
    url = url,
    method = "GET",
    sink = ltn12.sink.table(results),
    headers = {
        ["Cache-Control"] = "no-cache",
        ["X-Token"] = config.token
    }
})
Dilip
  • 628
  • 2
  • 10
  • 23
  • You're using `https.request` instead of `http.request` – hjpotter92 Aug 05 '14 at 22:35
  • Yes thats correct. In another thread(below) it says http.TIMEOUT should be used for https request as well. 'http://stackoverflow.com/questions/20193454/lua-https-timeout-is-not-working' – Dilip Aug 06 '14 at 04:06

1 Answers1

0

I also had problems getting the timeout for an https connection to work. Settings the timeout as http.TIMEOUT = ... is the correct thing to do, even for https (as confirmed when using very small timeouts).

In my case, DNS resolution was the culprit. This seems to happen synchronously without an enforced timeout from the lua side and will only time out when the syscall getaddrinfo (or whatever luasec uses internally) returns.

A workaround for me was to use the IP instead of the hostname in order to bypass DNS resolution. The timeout works for me then. Another option that could also help with your issue is to create a time-expiring thread for the connection.