add: use SO_REUSEPORT on platform supporting it#4703
add: use SO_REUSEPORT on platform supporting it#4703mkleczek wants to merge 1 commit intoPostgREST:mainfrom
Conversation
c252511 to
27c16d7
Compare
Hmm... worked before latest push. Will switch to draft and fix. |
@steve-chavez - it looks like the issue is that on my machine PostgREST startup is fast enough so that it loads the schema cache before it accepts any requests. Here in CI the new instance fails with The question: is there any particular reason why we return |
We were aiming to have requests wait instead of 503, this waiting does happen during schema cache reload but not on startup; we discussed this on #4129. Would it be better to not listen on the socket? How would clients behave in this case? |
|
They would get a "connection refused" error, which means nobody there and is imo more confusing that any 5xx error. UX-wise I would prefer some waiting to a presumably hard fail any day. |
I am not convinced, see below. This is a complex topic so let's dig into it a little more. The startup sequence right now is:
The alternatives are:
b - listening on a socket only after schema cache loaded
So from the point of view of the clients (they don't know when Postgrest was started), we have 3 alternatives:
I am not sure what value clients get from the first two options comparing to the third one. Diagnostics and readiness checks should be done using In case of
So the first two options cause disruptions whereas the third one is fully zero-downtime and transparent to the clients. My take on it would be:
This would require splitting binding from listening on the main socket (ie. we need to bind without listening first so that we can pass the socket to the admin server). @steve-chavez @develop7 thoughts? |
|
Dependent on resolving (or having a workaround to) yesodweb/wai#853 |
64bb6ca to
2cb6503
Compare
Agree, sounds much better. |
7d7375a to
bd4c7ec
Compare
acdac3c to
babc120
Compare
@mkleczek Q: why is the above dependent on yesodweb/wai#853? It looks like it can be done without it? |
@steve-chavez - changing startup sequence is independent and can be done now (will raise a PR, it should be easy thing to do). But this PR and prerequisite #4702 needs |
56a3d2f to
0212dc5
Compare
de2835b to
101e938
Compare
d185fcd to
7fc4acb
Compare
wolfgangwalther
left a comment
There was a problem hiding this comment.
Only looked at the second commit here.
| - Add config `db-timezone-enabled` for optional querying of timezones by @taimoorzaeem in #4751 | ||
| - Log schema cache queries timings on `log-level=debug` by @steve-chavez in #4805 | ||
| - Shutdown should wait for in flight requests by @mkleczek in #4702 | ||
| - Use SO_REUSEPORT on platforms supporting it by @mkleczek in #4703 #4694 |
There was a problem hiding this comment.
I started looking at this PR by looking at the changelog. As a user I wonder: "so what?". I have no idea what that means. The changelog should be user facing, not developer facing.
| assert ( | ||
| assert any( | ||
| "Failed to load the schema cache using db-schemas=public and db-extra-search-path=x" | ||
| in output[7] | ||
| in line | ||
| for line in output | ||
| ) |
There was a problem hiding this comment.
There seem to be some changes in here that make our io tests more robust to changes. These look uncontroversial, so if we split them separately, we can merge them much quicker.
| try @SomeException (bindPortGenEx reusePortOpts NS.Stream port hostPreference) | ||
| >>= either (const $ bindPortGenEx [] NS.Stream port hostPreference) pure | ||
| >>= listenSocket | ||
| where | ||
| reusePortOpts = [(NS.ReusePort, 1)] |
There was a problem hiding this comment.
Entirely optional nit: I find it easier to read when inlining reusePortOpts - will put the [ ... ] and [] right on top of each other, making it easy to see the "diff" there.
94919bc to
9b5cef7
Compare
There was a problem hiding this comment.
https://github.com/fpco/streaming-commons/blob/master/ChangeLog.md#0230 says it's in there since at least 0.2.3.0 (by fpco/streaming-commons#80); what lib (and Windows) version do you have in mind?
There was a problem hiding this comment.
https://github.com/fpco/streaming-commons/blob/master/ChangeLog.md#0230 says it's in there since at least 0.2.3.0 (by fpco/streaming-commons#80); what lib (and Windows) version do you have in mind?
The comment is copied from the exiting original code AFAIR - there is no change in streaming-commons usage.
341f183 to
00d3e4e
Compare

DISCLAIMER:
This commit was authored entirely by a human without the assistance of LLMs.
Fixes #4694
Stacked on top of #4702 as it is not enough to start a new instance, it is also necessary not to fail in-flight requests on the old instance.