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

PostgreSQL Name or service not known bug #820

Closed
jskorlol opened this issue Feb 25, 2024 · 6 comments
Closed

PostgreSQL Name or service not known bug #820

jskorlol opened this issue Feb 25, 2024 · 6 comments

Comments

@jskorlol
Copy link

Describe the bug
When executing with PostgreSQL, a DNS error occurs.

To Reproduce
Steps to reproduce the behavior:

  remotely:
    image: immybot/remotely:latest
    restart: unless-stopped
    labels:
      - "traefik.enable=false"
    volumes:
      - ../data:/app/AppData
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_HTTP_PORTS=5000
      - Remotely_ApplicationOptions__DbProvider=PostgreSQL
      - Remotely_ConnectionStrings__PostgreSQL=Server=Host=remotely.postgres;Port=5501;Database=remotely;Username=postgres;Password=test123!!@@~~;
    networks:
      backend:

  remotely.postgres:
    image: postgres:16.2
    restart: unless-stopped
    networks:
      backend:
        aliases:
          - remotely.postgres
    environment:
      - POSTGRES_DB=remotely
      - POSTGRES_PASSWORD=test123!!@@~~
    ports:
      - "5501:5432"

Remotely Version
v2024.02.22.1231

Expected Behavior
I have several Host values such as server.local and remotely.postgres. However, it seems that these Hosts are not being resolved correctly.

Unhandled exception. System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known
   at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, Nullable`1 startingTimestamp)
   at System.Net.Dns.<>c.<GetHostEntryOrAddressesCoreAsync>b__33_0(Object s, Int64 startingTimestamp)
   at System.Net.Dns.<>c__DisplayClass39_0`1.<RunAsync>b__0(Task <p0>, Object <p1>)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Npgsql.TaskTimeoutAndCancellation.ExecuteAsync(Func`2 getTaskFunc, NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.TaskTimeoutAndCancellation.ExecuteAsync[TResult](Func`2 getTaskFunc, NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.RawOpen(SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
   at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|213_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
   at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrationsAsync(CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in D:\a\1\s\Server\Program.cs:line 87
   at Program.<Main>(String[] args)
Unhandled exception. System.Net.Sockets.SocketException (00000005, 0xFFFDFFFF): Name or service not known
   at System.Net.Dns.GetHostEntryOrAddressesCore(String hostName, Boolean justAddresses, AddressFamily addressFamily, Nullable`1 startingTimestamp)
   at System.Net.Dns.<>c.<GetHostEntryOrAddressesCoreAsync>b__33_0(Object s, Int64 startingTimestamp)
   at System.Net.Dns.<>c__DisplayClass39_0`1.<RunAsync>b__0(Task <p0>, Object <p1>)
   at System.Threading.Tasks.ContinuationResultTaskFromTask`1.InnerInvoke()
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunFromThreadPoolDispatchLoop(Thread threadPoolThread, ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)
--- End of stack trace from previous location ---
   at Npgsql.TaskTimeoutAndCancellation.ExecuteAsync(Func`2 getTaskFunc, NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.TaskTimeoutAndCancellation.ExecuteAsync[TResult](Func`2 getTaskFunc, NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.ConnectAsync(NpgsqlTimeout timeout, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.RawOpen(SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
   at Npgsql.Internal.NpgsqlConnector.<Open>g__OpenCore|213_1(NpgsqlConnector conn, SslMode sslMode, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken, Boolean isFirstAttempt)
   at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenInternalAsync(Boolean errorsExpected, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenAsync(CancellationToken cancellationToken, Boolean errorsExpected)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlDatabaseCreator.Exists(Boolean async, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.ExistsAsync(CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Migrations.HistoryRepository.GetAppliedMigrationsAsync(CancellationToken cancellationToken)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Migrations.Internal.NpgsqlMigrator.MigrateAsync(String targetMigration, CancellationToken cancellationToken)
   at Program.<Main>$(String[] args) in D:\a\1\s\Server\Program.cs:line 87
   at Program.<Main>(String[] args)
  • [ v ] I am running Remotely in Docker and not on my QNAP, Synology, or Internet Connected Toaster
@Drehmini
Copy link

Hey @jskorlol ,

Were you able to make any figure this out? I'm having the same issue.

@PmPPolska
Copy link

PmPPolska commented Feb 28, 2024 via email

@JamiePhonic
Copy link

Can confirm with the following compose file:

version: '3.4'

networks:
  remotely:
    name: remotely-network
    driver: bridge
    ipam:
      config:
        - subnet: 172.28.0.0/16
          gateway: 172.28.0.1

services:
  pgdb:
    image: postgres:16
    restart: always
    environment:
      POSTGRES_USER: postgres
      POSTGRES_PASSWORD: {REDACTED}
      POSTGRES_DB: postgres
      PGDATA: /var/lib/postgresql/data
      TZ: Europe/London
    volumes:
      - /mnt/user/appdata/remotely/postgres:/var/lib/postgresql/data
    networks:
      remotely:
        ipv4_address: "172.28.0.2"
    
  app:
    image: immybot/remotely:latest
    volumes:
      - /mnt/user/appdata/remotely/server:/app/AppData
      - /mnt/user/appdata/remotely/aspnet:/root/.aspnet/
    restart: unless-stopped
    depends_on:
      - pgdb
    ports:
      - "5000:5000"
    networks:
      remotely:
        ipv4_address: "172.28.0.5"
    environment:
      - ASPNETCORE_ENVIRONMENT=Production
      - ASPNETCORE_HTTP_PORTS=5000
      # Other ASP.NET Core configurations can be overridden here, such as Logging.
      # See https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration/?view=aspnetcore-8.0

      # Values for DbProvider are SQLite, SQLServer, and PostgreSQL.
      - Remotely_ApplicationOptions__DbProvider=PostgreSQL
      # The Docker gateway will be used in Forwarded Headers, which is necessary to
      # to correctly determine request hostname and scheme within the app.  If you change
      # the network config, you must update this value as well.
      - Remotely_ApplicationOptions__DockerGateway=172.28.0.1
      # This path shouldn't be changed.  It points to the Docker volume.
      - Remotely_ConnectionStrings__SQLite=Data Source=/app/AppData/Remotely.db
      # If using SQL Server, change the connection string to point to your SQL Server instance.
      - Remotely_ConnectionStrings__SQLServer=Server=(localdb)\\mssqllocaldb;Database=Remotely-Server-53bc9b9d-9d6a-45d4-8429-2a2761773502;Trusted_Connection=True;MultipleActiveResultSets=true
      # If using PostgreSQL, change the connection string to point to your PostgreSQL instance.
      - Remotely_ConnectionStrings__PostgreSQL=Server=Host=pgdb;Database=Remotely;Username=postgres

@SMHRambo
Copy link
Contributor

Have the same problem

@SMHRambo
Copy link
Contributor

Found the problem!
I checked the soucecode and the Npgsql lib, the connection string is wrong.

Delete the "Server=" part of the connection string.

Remotely_ConnectionStrings__PostgreSQL=Server=Host=remotely_db;Port=5432;Database=remotely;Username=remotely;Password=changeme123;

must be

Remotely_ConnectionStrings__PostgreSQL=Host=remotely_db;Port=5432;Database=remotely;Username=remotely;Password=changeme123;

@darkpixel
Copy link

...and if you want to do it securely, tack on SSL Mode=Require; to the end.

bitbound added a commit that referenced this issue Jun 27, 2024
Solution for " PostgreSQL Name or service not known bug #820"
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

No branches or pull requests

6 participants