1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

async dns: correctly deal with cb killing wsi

This commit is contained in:
Andy Green 2021-02-05 13:09:33 +00:00
parent eb782bd41e
commit 24c0814fd3
5 changed files with 18 additions and 17 deletions

View file

@ -653,7 +653,7 @@ lws_sort_dns(struct lws *wsi, const struct addrinfo *result)
estr = _lws_route_est_outgoing(pt, &ds->dest);
if (!estr) {
lws_free(ds);
lwsl_notice("%s: no route out\n", __func__);
lwsl_info("%s: no route out\n", __func__);
/*
* There's no outbound route for this, it's
* unusable, so don't add it to the list

View file

@ -1424,7 +1424,7 @@ lws_vhost_destroy(struct lws_vhost *vh)
/* start async closure of all wsi on this pt thread attached to vh */
__lws_vhost_destroy_pt_wsi_dieback_start(vh);
lwsl_notice("%s: count_bound_wsi %d\n", __func__, vh->count_bound_wsi);
lwsl_info("%s: count_bound_wsi %d\n", __func__, vh->count_bound_wsi);
/* if there are none, finalize now since no further chance */
if (!vh->count_bound_wsi) {

View file

@ -554,7 +554,7 @@ lws_adns_parse_udp(lws_async_dns_t *dns, const uint8_t *pkt, size_t len)
q = lws_adns_get_query(dns, 0, &dns->waiting,
lws_ser_ru16be(pkt + DHO_TID), NULL);
if (!q) {
lwsl_notice("%s: dropping unknown query tid 0x%x\n",
lwsl_info("%s: dropping unknown query tid 0x%x\n",
__func__, lws_ser_ru16be(pkt + DHO_TID));
return;

View file

@ -136,8 +136,6 @@ lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q)
int m, n, which;
const char *name;
lwsl_notice("%s: %p\n", __func__, q);
/*
* We managed to get to the point of being WRITEABLE, which is not a
* given if no routes. So call off the write_sul timeout for that.
@ -160,7 +158,7 @@ lws_async_dns_writeable(struct lws *wsi, lws_adns_q_t *q)
lws_retry_sul_schedule_retry_wsi(wsi, &q->sul,
lws_async_dns_sul_cb_retry, &q->retry)) {
/* we have reached the end of our concealed retries */
lwsl_notice("%s: failing query\n", __func__);
lwsl_info("%s: failing query\n", __func__);
/*
* our policy is to force reloading the dns server info
* if our connection ever timed out, in case it or the
@ -256,7 +254,7 @@ qfail:
* incomplete cache entry
*/
if (q->firstcache) {
lwsl_notice("%s: destroy firstcache\n", __func__);
lwsl_debug("%s: destroy firstcache\n", __func__);
lws_adns_cache_destroy(q->firstcache);
q->firstcache = NULL;
}
@ -275,21 +273,21 @@ callback_async_dns(struct lws *wsi, enum lws_callback_reasons reason,
/* callbacks related to raw socket descriptor */
case LWS_CALLBACK_RAW_ADOPT:
lwsl_user("LWS_CALLBACK_RAW_ADOPT\n");
//lwsl_user("LWS_CALLBACK_RAW_ADOPT\n");
break;
case LWS_CALLBACK_RAW_CLOSE:
lwsl_user("LWS_CALLBACK_RAW_CLOSE\n");
//lwsl_user("LWS_CALLBACK_RAW_CLOSE\n");
break;
case LWS_CALLBACK_RAW_RX:
lwsl_user("LWS_CALLBACK_RAW_RX (%d)\n", (int)len);
//lwsl_user("LWS_CALLBACK_RAW_RX (%d)\n", (int)len);
// lwsl_hexdump_level(LLL_NOTICE, in, len);
lws_adns_parse_udp(dns, in, len);
break;
case LWS_CALLBACK_RAW_WRITEABLE:
lwsl_user("LWS_CALLBACK_RAW_WRITEABLE\n");
//lwsl_user("LWS_CALLBACK_RAW_WRITEABLE\n");
lws_start_foreach_dll_safe(struct lws_dll2 *, d, d1,
dns->waiting.head) {
lws_adns_q_t *q = lws_container_of(d, lws_adns_q_t,
@ -510,7 +508,7 @@ lws_async_dns_trim_cache(lws_async_dns_t *dns)
c1 = lws_container_of(lws_dll2_get_tail(&dns->cached),
lws_adns_cache_t, list);
if (c1->refcount)
lwsl_notice("%s: acache %p: refcount %d on purge\n",
lwsl_info("%s: acache %p: refcount %d on purge\n",
__func__, c1, c1->refcount);
else
lws_adns_cache_destroy(c1);
@ -660,16 +658,18 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name,
c = lws_adns_get_cache(dns, name);
if (c) {
lwsl_info("%s: %s: using cached, c->results %p\n", __func__, name, c->results);
lwsl_info("%s: %s: using cached, c->results %p\n", __func__,
name, c->results);
m = c->results ? LADNS_RET_FOUND : LADNS_RET_FAILED;
if (c->results)
c->refcount++;
if (cb(wsi, name, c->results, m, opaque) == NULL)
return LADNS_RET_FAILED_WSI_CLOSED;
return m;
} else
lwsl_notice("%s: %s uncached\n", __func__, name);
lwsl_info("%s: %s uncached\n", __func__, name);
/*
* It's a 1.2.3.4 or ::1 type IP address already? We don't need a dns
@ -843,7 +843,8 @@ lws_async_dns_query(struct lws_context *context, int tsi, const char *name,
failed:
lwsl_notice("%s: failed\n", __func__);
cb(wsi, NULL, NULL, LADNS_RET_FAILED, opaque);
if (!cb(wsi, NULL, NULL, LADNS_RET_FAILED, opaque))
return LADNS_RET_FAILED_WSI_CLOSED;
return LADNS_RET_FAILED;
}

View file

@ -88,10 +88,10 @@ static const struct async_dns_tests {
#if defined(LWS_WITH_IPV6)
{ "warmcat.com", LWS_ADNS_RECORD_AAAA, 16, /* check ipv6 */
{ 0x20, 0x01, 0x41, 0xd0, 0x00, 0x02, 0xee, 0x93,
0, 0, 0, 0, 0, 0, 0, 0, } },
0, 0, 0, 0, 0, 0, 0, 1, } },
{ "ipv6only.warmcat.com", LWS_ADNS_RECORD_AAAA, 16, /* check ipv6 */
{ 0x20, 0x01, 0x41, 0xd0, 0x00, 0x02, 0xee, 0x93,
0, 0, 0, 0, 0, 0, 0, 0, } },
0, 0, 0, 0, 0, 0, 0, 1, } },
#endif
};