From: Thomas Munro Date: Sat, 1 Mar 2025 00:56:33 +0000 (+1300) Subject: Work around OAuth/EVFILT_TIMER quirk on NetBSD. X-Git-Tag: REL_18_BETA1~719 X-Git-Url: http://git.postgresql.org/gitweb/?a=commitdiff_plain;h=c301a0a74a8aa9ec4fe1f364e05aa17a649f7260;p=postgresql.git Work around OAuth/EVFILT_TIMER quirk on NetBSD. 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 Discussion: https://postgr.es/m/CA%2BhUKGJ%2BWyJ26QGvO_nkgvbxgw%2B03U4EQ4Hxw%2BQBft6Np%2BXW7w%40mail.gmail.com --- diff --git a/src/interfaces/libpq/fe-auth-oauth-curl.c b/src/interfaces/libpq/fe-auth-oauth-curl.c index ae339579f88..6e60a81574d 100644 --- a/src/interfaces/libpq/fe-auth-oauth-curl.c +++ b/src/interfaces/libpq/fe-auth-oauth-curl.c @@ -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);