Re: [PATCH] OAuth: fix performance bug with stuck multiplexer events

Jacob Champion <jacob.champion@enterprisedb.com>

From: Jacob Champion <jacob.champion@enterprisedb.com>
To: Thomas Munro <thomas.munro@gmail.com>
Cc: PostgreSQL Hackers <pgsql-hackers@lists.postgresql.org>, Daniel Gustafsson <daniel@yesql.se>, Peter Eisentraut <peter@eisentraut.org>
Date: 2025-08-06T16:13:32Z
Lists: pgsql-hackers

Commits

Same data as JSON: GET /api/v1/messages/:b64id/commits the thread's linked commits as JSON, with link sources. API reference →
  1. oauth: Always link with -lm for floor()

  2. oauth: Add unit tests for multiplexer handling

  3. oauth: Ensure unused socket registrations are removed

  4. oauth: Remove expired timers from the multiplexer

  5. oauth: Remove stale events from the kqueue multiplexer

  6. oauth: Track total call count during a client flow

On Wed, Aug 6, 2025 at 8:04 AM Thomas Munro <thomas.munro@gmail.com> wrote:
>  * If it returns 1, then it stopped on the first level-triggered event
> that it rechecked and found to be still true.  Who cares if there are
> more that didn't get rechecked?  poll(fd) will report POLLIN either
> way, and that's what you want.

I think the weaker guarantee might be sufficient. I was trying to get
a stronger primitive in place so that we wouldn't have to worry about
it down the line, but it is a lot of code to pay...

One sharp edge of that strategy is caught by the new tests, which is
that if you call drain_socket_events() and then unset the timer, your
multiplexer is still readable until you call drain_socket_events() yet
again. At the moment, our code only ever calls those two in the
opposite order (due to the race condition pointed out in 0002); we'd
just have to keep that in mind. Maybe "drain" would no longer be the
verb to use there.

--Jacob