BUG/MEDIUM: httpclient: Throw an error if an lua httpclient instance is reused
It is not expected/supported to reuse an httpclient instance to process several requests. A new instance must be created for each request. However, in lua, there is nothing to prevent a user to create an httpclient object and use it in a loop to process requests. That's unfortunate because this will apparently work, the requests will be sent and a response will be received and processed. However internally some ressources will be allocated and never released. When the next response is processed, the ressources allocated for the previous one are definitively lost. In this patch we take care to check that the httpclient object was never used when a request is sent from a lua script by checking HTTPCLIENT_FS_STARTED flags. This flag is set when a httpclient applet is spawned to process a request and never removed after that. In lua, the httpclient applet is created when the request is sent. So, it is the right place to do this test. This patch should fix the issue #2986. It should be backported as far as 2.6.
This commit is contained in:
parent
94ded5523f
commit
50fca6f0b7
@ -8326,6 +8326,12 @@ __LJMP static int hlua_httpclient_send(lua_State *L, enum http_meth_t meth)
|
||||
|
||||
hlua_hc = hlua_checkhttpclient(L, 1);
|
||||
|
||||
/* An HTTPclient instance must never process more that one request. So
|
||||
* at this stage, it must never have been started.
|
||||
*/
|
||||
if (httpclient_started(hlua_hc->hc))
|
||||
WILL_LJMP(luaL_error(L, "httpclient instance cannot be reused. It must process at most one request"));
|
||||
|
||||
lua_pushnil(L); /* first key */
|
||||
while (lua_next(L, 2)) {
|
||||
if (strcmp(lua_tostring(L, -2), "dst") == 0) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user