Commit 5cdf8383 authored by Deomid Ryabkov's avatar Deomid Ryabkov Committed by Sergey Lyubka

Fix error handling in async resolver

    PUBLISHED_FROM=1e8558ec08f8e72d70163d34e0920f80f74372d1
parent 6418cad3
......@@ -7796,8 +7796,6 @@ static void mg_resolve_async_eh(struct mg_connection *nc, int ev, void *data) {
case MG_EV_CONNECT:
case MG_EV_POLL:
if (req->retries > req->max_retries) {
req->callback(NULL, req->data);
MG_FREE(req);
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
break;
}
......@@ -7812,13 +7810,28 @@ static void mg_resolve_async_eh(struct mg_connection *nc, int ev, void *data) {
if (mg_parse_dns(nc->recv_mbuf.buf, *(int *) data, msg) == 0 &&
msg->num_answers > 0) {
req->callback(msg, req->data);
} else {
req->callback(NULL, req->data);
nc->user_data = NULL;
MG_FREE(req);
}
MG_FREE(req);
MG_FREE(msg);
nc->flags |= MG_F_CLOSE_IMMEDIATELY;
break;
case MG_EV_SEND:
/*
* If a send error occurs, prevent closing of the connection by the core.
* We will retry after timeout.
*/
nc->flags &= ~MG_F_CLOSE_IMMEDIATELY;
mbuf_remove(&nc->send_mbuf, nc->send_mbuf.len);
break;
case MG_EV_CLOSE:
/* If we got here with request still not done, fire an error callback. */
if (req != NULL) {
req->callback(NULL, req->data);
nc->user_data = NULL;
MG_FREE(req);
}
break;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment