Work around OAuth/EVFILT_TIMER quirk on NetBSD.
authorThomas Munro <[email protected]>
Sat, 1 Mar 2025 00:56:33 +0000 (13:56 +1300)
committerThomas Munro <[email protected]>
Sat, 1 Mar 2025 01:41:02 +0000 (14:41 +1300)
NetBSD's EVFILT_TIMER doesn't like zero timeouts, as introduced by
commit b3f0be788.  Steal the workaround from the same problem on Linux
from a few lines up: round zero up to one.  Do this only for NetBSD, as
the other systems with the kevent() API accept zero and shouldn't have
to insert a small bogus wait.

Future improvement ideas:
 * when NetBSD < 10 falls out of support, we could try NODE_ABSTIME for
   the "fire now" meaning if timeout == 0
 * when libcurl tells us to start a 0ms timer and call it back, we could
   figure out how to handle that more directly without involving the
   kernel (the current architecture doesn't make that straightforward)

Failures with EINVAL errors could be seen on the new optional NetBSD CI
task that we're trying to keep green as a candidate for inclusion as
default-enabled CI task.  The NetBSD build farm animals aren't testing
OAuth yet, so no breakage there.

Reviewed-by: Jacob Champion <[email protected]>
Discussion: https://postgr.es/m/CA%2BhUKGJ%2BWyJ26QGvO_nkgvbxgw%2B03U4EQ4Hxw%2BQBft6Np%2BXW7w%40mail.gmail.com

src/interfaces/libpq/fe-auth-oauth-curl.c

index ae339579f88b54bd8bc409b30f571f5089b836d8..6e60a81574d1123ce76a3ed07234f99ca1dec47e 100644 (file)
@@ -1363,6 +1363,16 @@ set_timer(struct async_ctx *actx, long timeout)
 #ifdef HAVE_SYS_EVENT_H
    struct kevent ev;
 
+#ifdef __NetBSD__
+
+   /*
+    * Work around NetBSD's rejection of zero timeouts (EINVAL), a bit like
+    * timerfd above.
+    */
+   if (timeout == 0)
+       timeout = 1;
+#endif
+
    /* Enable/disable the timer itself. */
    EV_SET(&ev, 1, EVFILT_TIMER, timeout < 0 ? EV_DELETE : (EV_ADD | EV_ONESHOT),
           0, timeout, 0);