Skip to content

New function ares_process_fds()#875

Merged
bradh352 merged 4 commits intoc-ares:mainfrom
bradh352:process_fds
Sep 5, 2024
Merged

New function ares_process_fds()#875
bradh352 merged 4 commits intoc-ares:mainfrom
bradh352:process_fds

Conversation

@bradh352
Copy link
Member

@bradh352 bradh352 commented Sep 5, 2024

Add a new public function of ares_process_fds() to work around the shortcomings of ares_process_fd() and ares_process().

This new function allows integrators to specify more than one file descriptor at a time in an array, with an event mask per file descriptor. It also adds a flags parameter which can be used to skip extra expensive processing if they may be calling the function multiple times before waiting on more events.

This new function is used by the event thread, and all the other functions internally call this new function simplifying the code structure.

Authored-By: Brad House (@bradh352)

@bradh352 bradh352 merged commit 3b80588 into c-ares:main Sep 5, 2024
@bradh352 bradh352 deleted the process_fds branch September 5, 2024 14:49
@jmaggard10
Copy link

@bradh352 , this commit caused a regression, where now if I use the event thread and do two consecutive lookups with a dead server, the second lookup hangs forever. Please see the attached simple test program for a quick reproducer.
test-pr-875.zip

@jmaggard10
Copy link

jmaggard10 commented Jul 30, 2025

I was able to hack around it like this, but it's probably not the right way to approach it.

--- a/src/lib/ares_process.c
+++ b/src/lib/ares_process.c
@@ -26,6 +26,7 @@
  */
 
 #include "ares_private.h"
+#include "event/ares_event.h"
 
 #ifdef HAVE_STRINGS_H
 #  include <strings.h>
@@ -1333,6 +1334,14 @@ ares_status_t ares_send_query(ares_server_t *requested_server,
     ares_probe_failed_server(channel, server, query);
   }
 
+  /* If using the event thread backend, wake the event thread */
+  if (channel->optmask & ARES_OPT_EVENT_THREAD) {
+    ares_event_thread_t *e = channel->sock_state_cb_data;
+    if (e) {
+      ares_event_update(NULL, e, ARES_EVENT_FLAG_OTHER, NULL, ARES_SOCKET_BAD, NULL, NULL, NULL);
+    }
+  }
+
   return ARES_SUCCESS;
 }
 

@bhouse-nexthop
Copy link

@bradh352 , this commit caused a regression, where now if I use the event thread and do two consecutive lookups with a dead server, the second lookup hangs forever. Please see the attached simple test program for a quick reproducer. test-pr-875.zip

Do you think this is the same as #1000 ? I really meant to have time to look into that.

@jmaggard10
Copy link

@bradh352 , this commit caused a regression, where now if I use the event thread and do two consecutive lookups with a dead server, the second lookup hangs forever. Please see the attached simple test program for a quick reproducer. test-pr-875.zip

Do you think this is the same as #1000 ? I really meant to have time to look into that.

Oh, yes that's exactly the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants