-
Notifications
You must be signed in to change notification settings - Fork 74
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
Ignored port
from config in Windows
#38
Comments
That's very strange. I don't have convenient access to test this on Windows, but I don't see what could be different between *nix and Windows here. |
It seems that the problem you are experiencing is due to the port setting in your tern configuration. The error indicates that the connection is trying to use the default port (5432), ignoring the specified port (5431). This can occur for various reasons, including the way environment variables are interpreted or how the connection string is configured. [database]
user=test1
password=root
conn_string = host=127.0.0.1 port=5431 dbname=test_dev_01 connect_timeout=10 |
I can confirm that bug (currently on Windows): If sslmode is not set, tern does not pick up port in tern.conf or command line |
@jackc I think I found the root cause for this error. The port is properly read from config file or cli argument, but when a connectionis created here: Lines 1062 to 1063 in 160bdb3
a fallback connection is created as well. In the next steps some config arguments are overwritten with args from file or args from cli Line 1082 in 160bdb3
and Line 1098 in 160bdb3
The config is still correct, but the port is not set in Config.Fallbacks[0]: If Incase Lines 155 to 175 in 160bdb3
and the Fallbacks are copied to the config. To solve this, I see these options:
I consider a rewrite of LoadConfig to first load the arguments, merge them and then create the config the cleanest approach, but the one with the most changes. Do you have an opinion about which options is best? I would prepare the PR. |
If the sslmode was blank then some of the fallback config was not being set properly. This was because blank is treated as "prefer" by pgx (which follows libpq's behavior). But tern parsing parsing the config in several places and then trying to fix the fallback config. It missed the default "prefer" case. The solution was to avoid the multiple parsing and fallback config logic entirely. Instead, we set the PG* environment variables from the CLI options and config file before parsing the conn string. #38
Thanks for the in-depth analysis.
I think this is the best approach. Take a look at #107. |
Thanks a lot , #107 looks like it does what i need. Do you need my help on anything? |
Just merged it into master.
If you can test master and make sure it works that would help. |
I can confirm this works as expected:
I am unsure about this:
|
I'm not sure either. My expectation is that the priority is CLI arg, config file, then envvar. But I'm not sure where that idea came from. It may or may not be standard expectation. |
My expectation is different (highest priority first):
The rational is: The more ad-hoc the parameter can be set / the more ephermal it is the higher the priority. But expectations may be different. Let's keep it the way it is, usually I use config file and cli args,so env vars is an edge case for me. Thanks for your effort. |
👍 Just tagged v2.2.2 with this fix. |
Windows 11 Pro N, 21H2
Tern: 1.12.5
PostgreSQL 13.4 in Docker for Windows.
Docker uses WSL2 as a backend.
WSL OS: Fedora Server 34.
Port mapping in docker enabled: 5432 container -> 5431 host.
I built two different binaries: for unix:amd/64, windows:amd/64.
If I run an unix's binary it's OK. It can connect, do necessary work, etc.
If I run window's binary I getting an error "Failed to connect" and I see a default pg port: 5432, not those which is specified in config.
Output:
tern.conf
The text was updated successfully, but these errors were encountered: