- status = getaddrinfo(node, service, &ai_hints, &ai_list);
- if (status != 0) {
- ERROR("write_tsdb plugin: getaddrinfo (%s, %s) failed: %s", node, service,
- gai_strerror(status));
- return -1;
+ if (NULL == cb->sock_info) {
+ struct addrinfo ai_hints = {
+ .ai_family = AF_UNSPEC,
+ .ai_flags = AI_ADDRCONFIG,
+ .ai_socktype = SOCK_STREAM,
+ };
+
+ if ((cb->sock_info_last_update + dnsttl) >= now) {
+ DEBUG("write_tsdb plugin: too many getaddrinfo (%s, %s) failures", node,
+ service);
+ return (-1);
+ }
+
+ cb->sock_info_last_update = now;
+ status = getaddrinfo(node, service, &ai_hints, &(cb->sock_info));
+ if (status != 0) {
+ if (cb->sock_info) {
+ freeaddrinfo(cb->sock_info);
+ cb->sock_info = NULL;
+ }
+ if (cb->connect_failed_log_enabled) {
+ ERROR("write_tsdb plugin: getaddrinfo (%s, %s) failed: %s", node,
+ service, gai_strerror(status));
+ cb->connect_failed_log_enabled = 0;
+ }
+ return -1;
+ }