diff --git a/src/lib/ares_process.c b/src/lib/ares_process.c index d73a6fd9..f1001105 100644 --- a/src/lib/ares_process.c +++ b/src/lib/ares_process.c @@ -996,9 +996,28 @@ ares_status_t ares__send_query(struct query *query, struct timeval *now) } conn = ares__llist_node_val(node); + if (ares__socket_write(channel, conn->fd, query->qbuf, query->qlen) == -1) { - /* FIXME: Handle EAGAIN here since it likely can happen. */ - status = ARES_ESERVFAIL; + if (try_again(SOCKERRNO)) { + status = ARES_ESERVFAIL; + } else { + status = ARES_ECONNREFUSED; + } + + if (status == ARES_ECONNREFUSED) { + handle_conn_error(conn, ARES_TRUE, status); + + /* This query wasn't yet bound to the connection, need to manually + * requeue it and return an appropriate error */ + status = ares__requeue_query(query, now, status); + if (status == ARES_ETIMEOUT) { + status = ARES_ECONNREFUSED; + } + return status; + } + + /* FIXME: Handle EAGAIN here since it likely can happen. Right now we + * just requeue to a different server/connection. */ server_increment_failures(server); status = ares__requeue_query(query, now, status);