-
Notifications
You must be signed in to change notification settings - Fork 458
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(compute_ctl): Allow usage of DB names with whitespaces #9919
Conversation
76574a7
to
ced563e
Compare
I wonder, is the way I did it this time is also OK, because I'm not sure how to switch to |
6952 tests run: 6644 passed, 0 failed, 308 skipped (full report)Code coverage* (full report)
* collected from Rust tests only The comment gets automatically updated with the latest test results
5b68765 at 2024-11-28T20:17:03.326Z :recycle: |
is it possible to add a test? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good at high level. Please add test and address all the minor comments though
+1. The |
Let's put out the fire first, but let's also consider if this is actually an upstream bug in tokio-postgres, and submit a fix there too. |
We use `set_path()` to replace the database name in the connection string. It automatically does url-safe encoding if path is not already encoded, but it does it as per the URL standard, which assumes that tabs can be safely removed from the path without changing the meaning of the URL. See, e.g., https://url.spec.whatwg.org/#concept-basic-url-parser Yet, this is not true for Postgres, where it's completely valid to have trailing tabs in the database name. Here, we first encode the database name Resolves neondatabase/cloud#20869
2509e3a
to
ff914f3
Compare
Added a python test instead for now. It fails in main and passes with my changes. There are many places, and I'm afraid that with some future refactoring someone will use a set_path() again in some of the places. +1 for writing more unit tests and doing some further refactoring, but will keep it for further work Also, this python test checks that we can actually create and configure databases via spec, which I think is good to catch regressions right in the neon test suite |
@hlinnaka What do you mean by upstream bug in |
Going to merge when CI is ready |
Oh right, I somehow thought this was in tokio-postgres. Never mind |
returns |
3ee8e47
to
5b68765
Compare
It's still bad. I think I've finally got rid of messing with urls everywhere, so just dropped this helper |
Unify the way we connect to Postgres: 1. Switch to building configs everywhere 2. Always set `application_name` and make naming consistent Follow-up for #9919
## Problem It was not always possible to judge what exactly some `cloud_admin` connections were doing because we didn't consistently set `application_name` everywhere. ## Summary of changes Unify the way we connect to Postgres: 1. Switch to building configs everywhere 2. Always set `application_name` and make naming consistent Follow-up for #9919 Part of neondatabase/cloud#20948
## Problem We used `set_path()` to replace the database name in the connection string. It automatically does url-safe encoding if the path is not already encoded, but it does it as per the URL standard, which assumes that tabs can be safely removed from the path without changing the meaning of the URL. See, e.g., https://url.spec.whatwg.org/#concept-basic-url-parser. It also breaks for DBs with properly %-encoded names, like with `%20`, as they are kept intact, but actually should be escaped. Yet, this is not true for Postgres, where it's completely valid to have trailing tabs in the database name. I think this is the PR that caused this regression #9717, as it switched from `postgres::config::Config` back to `set_path()`. This was fixed a while ago already [1], btw, I just haven't added a test to catch this regression back then :( ## Summary of changes This commit changes the code back to use `postgres/tokio_postgres::Config` everywhere. While on it, also do some changes around, as I had to touch this code: 1. Bump some logging from `debug` to `info` in the spec apply path. We do not use `debug` in prod, and it was tricky to understand what was going on with this bug in prod. 2. Refactor configuration concurrency calculation code so it was reusable. Yet, still keep `1` in the case of reconfiguration. The database can be actively used at this moment, so we cannot guarantee that there will be enough spare connection slots, and the underlying code won't handle connection errors properly. 3. Simplify the installed extensions code. It was spawning a blocking task inside async function, which doesn't make much sense. Instead, just have a main sync function and call it with `spawn_blocking` in the API code -- the only place we need it to be async. 4. Add regression python test to cover this and related problems in the future. Also, add more extensive testing of schema dump and DBs and roles listing API. [1]: 4d1e48f [2]: https://www.postgresql.org/message-id/flat/20151023003445.931.91267%40wrigleys.postgresql.org Resolves neondatabase/cloud#20869
## Problem It was not always possible to judge what exactly some `cloud_admin` connections were doing because we didn't consistently set `application_name` everywhere. ## Summary of changes Unify the way we connect to Postgres: 1. Switch to building configs everywhere 2. Always set `application_name` and make naming consistent Follow-up for #9919 Part of neondatabase/cloud#20948
Problem
We used
set_path()
to replace the database name in the connection string. It automatically does url-safe encoding if the path is not already encoded, but it does it as per the URL standard, which assumes that tabs can be safely removed from the path without changing the meaning of the URL. See, e.g., https://url.spec.whatwg.org/#concept-basic-url-parser. It also breaks for DBs with properly %-encoded names, like with%20
, as they are kept intact, but actually should be escaped.Yet, this is not true for Postgres, where it's completely valid to have trailing tabs in the database name.
I think this is the PR that caused this regression #9717, as it switched from
postgres::config::Config
back toset_path()
.This was fixed a while ago already 1, btw, I just haven't added a test to catch this regression back then :(
Summary of changes
This commit changes the code back to use
postgres/tokio_postgres::Config
everywhere.While on it, also do some changes around, as I had to touch this code:
debug
toinfo
in the spec apply path. We do not usedebug
in prod, and it was tricky to understand what was going on with this bug in prod.1
in the case of reconfiguration. The database can be actively used at this moment, so we cannot guarantee that there will be enough spare connection slots, and the underlying code won't handle connection errors properly.spawn_blocking
in the API code -- the only place we need it to be async.Resolves neondatabase/cloud#20869