--- syslog-ng-3.11.1.orig/configure.ac
+++ syslog-ng-3.11.1/configure.ac
@@ -701,6 +701,7 @@ AC_CHECK_LIB(rt, nanosleep, BASE_LIBS="$
 AC_CHECK_LIB(nsl, gethostbyname, BASE_LIBS="$BASE_LIBS -lnsl")
 AC_CHECK_LIB(regex, regexec, REGEX_LIBS="-lregex")
 AC_CHECK_LIB(resolv, res_init, RESOLV_LIBS="-lresolv")
+AC_CHECK_LIB(anl, getaddrinfo_a, RESOLV_LIBS="-lanl")
 
 AC_CHECK_FUNCS(strdup		\
 	strtol			\
--- syslog-ng-3.11.1.orig/lib/host-resolve.c
+++ syslog-ng-3.11.1/lib/host-resolve.c
@@ -135,17 +135,57 @@ resolve_wildcard_hostname_to_sockaddr(GS
 
 #ifdef SYSLOG_NG_HAVE_GETADDRINFO
 static gboolean
-resolve_hostname_to_sockaddr_using_getaddrinfo(GSockAddr **addr, gint family, const gchar *name)
+resolve_hostname_to_sockaddr_using_getaddrinfo(GSockAddr **addr, gint family, const gchar *name, struct gaicb **request)
 {
   struct addrinfo hints;
   struct addrinfo *res;
+  struct addrinfo *hints_ptr;
+  gboolean resolved = FALSE;
+  int ret;
 
   memset(&hints, 0, sizeof(hints));
   hints.ai_family = family;
   hints.ai_socktype = 0;
   hints.ai_protocol = 0;
 
-  if (getaddrinfo(name, NULL, &hints, &res) == 0)
+  if (request == NULL) {
+     resolved = (getaddrinfo(name, NULL, &hints, &res) == 0);
+  } else {
+     if (request[0] == NULL) {
+        request[0] = g_new0(struct gaicb, 1);
+	request[0]->ar_name = strdup(name);
+
+        hints_ptr = g_new0(struct addrinfo, 1);
+	request[0]->ar_request = hints_ptr;
+	memcpy(hints_ptr, &hints, sizeof(hints));
+        ret = getaddrinfo_a(GAI_NOWAIT, request, 1, NULL);
+        if (ret) {
+           msg_error("Unable to queue address resolution request",
+                     evt_tag_str("error", gai_strerror(ret)));
+           goto failure_free;
+        }
+     } else {
+        ret = gai_error(*request);
+        if (ret) {
+           if (ret != EAI_INPROGRESS) {
+              msg_error("Failed resolution",
+                     evt_tag_str("address",name),
+                     evt_tag_str("error", gai_strerror(ret)));
+              goto failure_free;
+           }
+           msg_error("Resolution still in progress...",
+                     evt_tag_str("address",name));
+           return FALSE;
+        }
+	res = request[0]->ar_result;
+	g_free(hints_ptr);
+	g_free(request[0]);
+	request[0] = NULL;
+        resolved = TRUE;
+     }
+  }
+
+  if (resolved)
     {
       /* we only use the first entry in the returned list */
       switch (family)
@@ -163,9 +203,15 @@ resolve_hostname_to_sockaddr_using_getad
           break;
         }
       freeaddrinfo(res);
-      return TRUE;
     }
-  return FALSE;
+
+  return resolved;
+
+failure_free:
+   g_free(hints_ptr);
+   g_free(request[0]);
+   request[0] = NULL;
+   return FALSE;
 }
 
 #else
@@ -202,7 +248,7 @@ resolve_hostname_to_sockaddr_using_getho
 #endif
 
 gboolean
-resolve_hostname_to_sockaddr(GSockAddr **addr, gint family, const gchar *name)
+resolve_hostname_to_sockaddr(GSockAddr **addr, gint family, const gchar *name, struct gaicb **req)
 {
   gboolean result;
 
@@ -210,11 +256,11 @@ resolve_hostname_to_sockaddr(GSockAddr *
     return resolve_wildcard_hostname_to_sockaddr(addr, family, name);
 
 #ifdef SYSLOG_NG_HAVE_GETADDRINFO
-  result = resolve_hostname_to_sockaddr_using_getaddrinfo(addr, family, name);
+  result = resolve_hostname_to_sockaddr_using_getaddrinfo(addr, family, name, req);
 #else
   result = resolve_hostname_to_sockaddr_using_gethostbyname(addr, family, name);
 #endif
-  if (!result)
+  if (!result && req == NULL)
     {
       msg_error("Error resolving hostname",
                 evt_tag_str("host", name));
--- syslog-ng-3.11.1.orig/lib/host-resolve.h
+++ syslog-ng-3.11.1/lib/host-resolve.h
@@ -25,6 +25,7 @@
 
 #include "syslog-ng.h"
 #include "gsockaddr.h"
+#include <netdb.h>
 
 typedef struct _HostResolveOptions
 {
@@ -36,7 +37,7 @@ typedef struct _HostResolveOptions
 
 /* name resolution */
 const gchar *resolve_sockaddr_to_hostname(gsize *result_len, GSockAddr *saddr, const HostResolveOptions *host_resolve_options);
-gboolean resolve_hostname_to_sockaddr(GSockAddr **addr, gint family, const gchar *name);
+gboolean resolve_hostname_to_sockaddr(GSockAddr **addr, gint family, const gchar *name, struct gaicb **req);
 const gchar *resolve_hostname_to_hostname(gsize *result_len, const gchar *hostname, HostResolveOptions *options);
 
 void host_resolve_options_defaults(HostResolveOptions *options);
--- syslog-ng-3.11.1.orig/lib/tests/test_host_resolve.c
+++ syslog-ng-3.11.1/lib/tests/test_host_resolve.c
@@ -120,7 +120,7 @@ assert_hostname_to_sockaddr(gint family,
   gchar ip[64];
   gboolean result;
 
-  result = resolve_hostname_to_sockaddr(&sa, family, hostname);
+  result = resolve_hostname_to_sockaddr(&sa, family, hostname, NULL);
   if (sa)
     {
       g_sockaddr_format(sa, ip, sizeof(ip), GSA_ADDRESS_ONLY);
@@ -138,7 +138,7 @@ assert_hostname_to_sockaddr_fails(gint f
   GSockAddr *sa = NULL;
   gboolean result;
 
-  result = resolve_hostname_to_sockaddr(&sa, family, hostname);
+  result = resolve_hostname_to_sockaddr(&sa, family, hostname, NULL);
   g_sockaddr_unref(sa);
 
   assert_null(sa, "returned sockaddr is non-NULL");
--- syslog-ng-3.11.1.orig/modules/afsocket/afinet-dest.c
+++ syslog-ng-3.11.1/modules/afsocket/afinet-dest.c
@@ -163,13 +163,13 @@ afinet_dd_setup_addresses(AFSocketDestDr
   g_sockaddr_unref(self->super.bind_addr);
   g_sockaddr_unref(self->super.dest_addr);
 
-  if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip))
+  if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip, &s->request))
     return FALSE;
 
   if (self->bind_port)
     g_sockaddr_set_port(self->super.bind_addr, afinet_lookup_service(self->super.transport_mapper, self->bind_port));
 
-  if (!resolve_hostname_to_sockaddr(&self->super.dest_addr, self->super.transport_mapper->address_family, self->hostname))
+  if (!resolve_hostname_to_sockaddr(&self->super.dest_addr, self->super.transport_mapper->address_family, self->hostname, &s->request))
     return FALSE;
 
   if (!self->dest_port)
--- syslog-ng-3.11.1.orig/modules/afsocket/afinet-source.c
+++ syslog-ng-3.11.1/modules/afsocket/afinet-source.c
@@ -72,7 +72,7 @@ afinet_sd_setup_addresses(AFSocketSource
 
   g_sockaddr_unref(self->super.bind_addr);
 
-  if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip))
+  if (!resolve_hostname_to_sockaddr(&self->super.bind_addr, self->super.transport_mapper->address_family, self->bind_ip, NULL))
     return FALSE;
 
   if (!self->bind_port)
--- syslog-ng-3.11.1.orig/modules/afsocket/afsocket-dest.h
+++ syslog-ng-3.11.1/modules/afsocket/afsocket-dest.h
@@ -45,6 +45,7 @@ struct _AFSocketDestDriver
   LogWriterOptions writer_options;
   LogProtoClientFactory *proto_factory;
 
+  struct gaicb *request;
   GSockAddr *bind_addr;
   GSockAddr *dest_addr;
   gint time_reopen;
--- syslog-ng-3.11.1.orig/modules/afstomp/stomp.c
+++ syslog-ng-3.11.1/modules/afstomp/stomp.c
@@ -107,7 +107,7 @@ stomp_connect(stomp_connection **connect
       return FALSE;
     }
 
-  if (!resolve_hostname_to_sockaddr(&conn->remote_sa, AF_INET, hostname))
+  if (!resolve_hostname_to_sockaddr(&conn->remote_sa, AF_INET, hostname, NULL))
     {
       msg_error("Failed to resolve hostname in stomp driver",
                 evt_tag_str("hostname", hostname));
