Skip to content
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

port ignored in tern.conf #63

Closed
sobafuchs opened this issue Jul 21, 2022 · 9 comments · Fixed by #75
Closed

port ignored in tern.conf #63

sobafuchs opened this issue Jul 21, 2022 · 9 comments · Fixed by #75

Comments

@sobafuchs
Copy link

sobafuchs commented Jul 21, 2022

System: macOS Monterey version 12.4
tern version: 1.13.0

I'm currently facing a weird issue where port is being ignored in tern.conf. I specified it to be 9200 and tern still uses 5432. I have a docker-compose file that looks like this:

version: "3"
services:
  db:
    container_name: postgres
    restart: always
    image: postgres
    volumes:
      - postgres_data:/var/lib/postgresql/data
    environment:
      POSTGRES_DB: tern_test
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: postgres
    ports:
      - "9200:5432"
volumes:
  postgres_data:

I started this up in a separate terminal with docker-compose up, I can confirm the pg server is up and running and listening for connections. I then have the following tern.conf:

[database]
host = 127.0.0.1
port = 9200
database = tern_test
user = postgres
password = {{env "MIGRATOR_PASSWORD"}}
sslmode = prefer

When I run tern with MIGRATOR_PASSWORD=postgres tern migrate, I get the following error:

Unable to connect to PostgreSQL:
  failed to connect to `host=127.0.0.1 user=postgres database=tern_test`: dial error (dial tcp 127.0.0.1:5432: connect: connection refused)

If I change my docker-compose.yml to expose it on local port 5432, it works of course. I've also tried other ports and it only uses 5432. I'm using macOS Monterey version 12.4 (I saw another issue here specific to Windows, not sure if the OS is even relevant here).

@jackc
Copy link
Owner

jackc commented Jul 23, 2022

I'm on MacOS Monterey 12.4 as well, but I am unable to reproduce the issue. I'm not using docker though. Just tern and PostgreSQL on the same machine.

Does it work if you pass port as a CLI option? What about the other settings in tern.conf? Are they definitely being read? The config file is optional so maybe it isn't being read at all.


Maybe related to #38.

@sobafuchs
Copy link
Author

sobafuchs commented Jul 25, 2022

It has the same issue if I pass it in as a CLI option:

~/projects/code/personal/tern-issue $ tern migrate --database tern_test --port 9200 --user postgres --password postgres --host 127.0.0.1

Unable to connect to PostgreSQL:
  failed to connect to `host=127.0.0.1 user=postgres database=tern_test`: dial error (dial tcp 127.0.0.1:5432: connect: connection refused)

Looks like the other options do get read, just not the port.

If I just use the pure config file, the other options definitely do get read. For instance, if you check the original error message in the issue, it is using the correct database name.

@sobafuchs
Copy link
Author

sobafuchs commented Jul 25, 2022

I was able to reproduce on Ubuntu as well. Here's the output from uname -a:

Linux 5.4.0-122-generic #138-Ubuntu SMP Wed Jun 22 15:00:31 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Definitely don't think this is OS-related. Whether or not postgres is containerized or not shouldn't be relevant though no? Does tern do some type of port scanning before using a port?

@sobafuchs
Copy link
Author

sobafuchs commented Jul 25, 2022

I can confirm tern uses the correct port if I remove my tern.conf file (as in delete it entirely) and pass all the options to the CLI. If the tern.conf file exists and I pass the options through the CLI, it uses the wrong port

@jackc
Copy link
Owner

jackc commented Jul 30, 2022

I'm at a bit of a loss as to what could be happening. Could you step through in a debugger? Maybe something would become apparent then.

@Bindernews
Copy link

I had the same issue, workaround for me was specifying conn_string instead of all the other fields. I may look at it later and see if I can debug the issue.

@jackc
Copy link
Owner

jackc commented Feb 24, 2023

Still unable to reproduce. I'm using the latest v2-dev.

@abs3ntdev
Copy link
Contributor

I can replicate this behavior. Tern always uses 5432 regardless of what port is present in the config file, even deleting the port value from the config file and passing by flag does not work. Deleting the entire config file and passing all values by flag makes it work.

@smainz
Copy link

smainz commented Sep 4, 2024

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
If you set sslmode = prefer tern picks up the port both in tern.conf or command line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants