{"record":{"id":"68b9d858d1accb71","repo":"nodejs/node","slug":"select-fail-d","errorCode":null,"errorMessage":"select fail: %d","messagePattern":"select fail: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"deps/cares/src/tools/adig.c","lineNumber":900,"sourceCode":"    memset(&tv, 0, sizeof(tv));\n\n    nfds = ares_fds(channel, &read_fds, &write_fds);\n    if (nfds == 0) {\n      break;\n    }\n    tvp = ares_timeout(channel, NULL, &tv);\n    if (tvp == NULL) {\n      break;\n    }\n    count = select(nfds, &read_fds, &write_fds, NULL, tvp);\n    if (count < 0) {\n#ifdef USE_WINSOCK\n      int err = WSAGetLastError();\n#else\n      int err = errno;\n#endif\n      if (err != EAGAIN && err != EINTR) {\n        fprintf(stderr, \"select fail: %d\", err);\n        return 1;\n      }\n    }\n    ares_process(channel, &read_fds, &write_fds);\n  }\n  return 0;\n}\n\ntypedef enum {\n  OPT_TYPE_BOOL,\n  OPT_TYPE_STRING,\n  OPT_TYPE_SIZE_T,\n  OPT_TYPE_U16,\n  OPT_TYPE_FUNC\n} opt_type_t;\n\n/* Callback called with OPT_TYPE_FUNC when processing options.\n * \\param[in] prefix  prefix character for option","sourceCodeStart":882,"sourceCodeEnd":918,"githubUrl":"https://github.com/nodejs/node/blob/1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e/deps/cares/src/tools/adig.c#L882-L918","documentation":"Printed by the adig tool's event loop at adig.c:900 when the select() system call returns a negative value (count < 0) and the error is neither EAGAIN nor EINTR. The message includes the numeric errno value. On Windows it uses WSAGetLastError(), on other platforms errno. The tool returns 1 (failure), terminating the DNS query loop. select() monitors the file descriptors that c-ares is watching for DNS response traffic.","triggerScenarios":"The select() call in adig's event_loop (line 892) fails with an unrecoverable error. This happens when the file descriptor set passed to select() contains an invalid FD (EBADF), the nfds argument exceeds the process's FD limit, or the system call is interrupted by a signal that is not EINTR/EAGAIN. On Windows, a WinSock error such as WSAENOTSOCK or WSAEINVAL triggers it.","commonSituations":"Running adig in a container or sandbox with restricted file descriptor limits. A c-ares channel has internal sockets that were closed out from under it (double-close, use-after-close). A misconfigured seccomp filter blocks select(). Running on a platform where select() has platform-specific quirks (very large FD numbers).","solutions":["Check the numeric errno printed: EBADF (9) means an invalid FD — investigate whether c-ares sockets were prematurely closed.","Increase the file descriptor limit with 'ulimit -n' if nfds exceeds the soft limit.","If running in a container, verify the seccomp profile and namespace settings allow select() and socket operations.","Ensure only one thread is using the c-ares channel and that ares_destroy is not called concurrently with the event loop."],"exampleFix":"// before: event loop fails on select error\n// adig example.com  // prints 'select fail: 9' (EBADF)\n\n// after: check fd limits and channel lifecycle\nulimit -n 65536       // raise fd limit\n// ensure ares_destroy(channel) is called only after event_loop returns","handlingStrategy":"validation","validationCode":"// Before entering the event loop, check fd limits\n#include <sys/resource.h>\nstruct rlimit rl;\nif (getrlimit(RLIMIT_NOFILE, &rl) == 0) {\n    if (rl.rlim_cur < 1024) {\n        rl.rlim_cur = rl.rlim_max;\n        setrlimit(RLIMIT_NOFILE, &rl);\n    }\n}\n// Ensure the c-ares channel is valid and not destroyed concurrently","typeGuard":null,"tryCatchPattern":"// In the event loop, handle EAGAIN/EINTR gracefully (adig already does this)\n// For other errors, log errno and break rather than crash\ncount = select(nfds, &read_fds, &write_fds, NULL, tvp);\nif (count < 0 && errno != EAGAIN && errno != EINTR) {\n    // log errno, clean up channel, exit gracefully\n    break;\n}","preventionTips":["Raise file descriptor limits (ulimit -n) before running DNS tools in production.","Ensure ares_destroy() is not called concurrently with the event loop.","Verify container seccomp profiles allow select() and socket operations."],"tags":["c-ares","adig","select","errno","event-loop","network"],"backgroundTag":null,"analyzedSha":"1b2de5e052fc0fb95fd7fb6846dcec4ade598e9e","analyzedAt":"2026-08-13T00:53:24.642Z","schemaVersion":2},"datasetVersion":"2026-08-13T04:17:16.726Z"}