* from the cache. */
static void purge_expired_resolves(uint32_t now) {
struct cached_resolve *resolve;
+ struct pending_connection_t *pend;
+ connection_t *pendconn;
/* this is fast because the linked list
* oldest_cached_resolve is ordered by when they came in.
log(LOG_DEBUG,"Forgetting old cached resolve (expires %lu)", (unsigned long)resolve->expire);
if(resolve->state == CACHE_STATE_PENDING) {
log_fn(LOG_WARN,"Expiring a dns resolve that's still pending. Forgot to cull it?");
- /* XXX if resolve->pending_connections is used, then we're probably
- * introducing bugs by closing resolve without notifying those streams.
- */
+ }
+ if (resolve->pending_connections) {
+ log_fn(LOG_WARN, "Closing pending connections on expiring DNS resolve!");
+ while (resolve->pending_connections) {
+ pend = resolve->pending_connections;
+ resolve->pending_connections = pend->next;
+ /* Connections should only be pending if they have no socket. */
+ tor_assert(pend->conn->s == -1);
+ pendconn = pend->conn;
+ connection_edge_end(pendconn, END_STREAM_REASON_MISC,
+ pendconn->cpath_layer);
+ connection_mark_for_close(pendconn);
+ connection_free(pendconn);
+ tor_free(pend);
+ }
}
oldest_cached_resolve = resolve->next;
if(!oldest_cached_resolve) /* if there are no more, */
struct in_addr in;
uint32_t now = time(NULL);
assert_connection_ok(exitconn, 0);
+ tor_assert(exitconn->s == -1);
/* first check if exitconn->address is an IP. If so, we already
* know the answer. */
unsigned char len;
tor_assert(exitconn->state == EXIT_CONN_STATE_RESOLVING);
+ tor_assert(exitconn->s == -1);
spawn_enough_dnsworkers(); /* respawn here, to be sure there are enough */
pend;
pend = pend->next) {
assert_connection_ok(pend->conn, 0);
+ tor_assert(pend->conn->s == -1);
+ tor_assert(!connection_in_array(pend->conn));
}
}
}
pend->conn->state = EXIT_CONN_STATE_RESOLVEFAILED;
pendconn = pend->conn; /* don't pass complex things to the
connection_mark_for_close macro */
+ tor_assert(pendconn->s == -1);
if(!pendconn->marked_for_close) {
connection_edge_end(pendconn, END_STREAM_REASON_MISC, pendconn->cpath_layer);
connection_mark_for_close(pendconn);
}
+ connection_free(pendconn);
resolve->pending_connections = pend->next;
tor_free(pend);
}
assert_connection_ok(pend->conn,time(NULL));
pend->conn->addr = resolve->addr;
-
if(resolve->state == CACHE_STATE_FAILED) {
pendconn = pend->conn; /* don't pass complex things to the
connection_mark_for_close macro */