Error the when connecting to server db / making requests

Hi, I've recently started getting an error when trying to make requests to my server.

I suspect this has to do with Fluent (I'm using psql) but honestly not sure what is the root cause. I am getting the same issue with a project I have been working on for a couple of weeks and on a new test project.

The server starts up fine with no errors. However, when trying to make any requests I get this error. It also occurs when running tests.

2025-03-25T23:11:55+0000 error codes.vapor.application : database-id=psql [AsyncKit] Opening new connection for pool failed: PSQLError(code: connectionError, underlying: NIOPosix.NIOConnectionError(host: "localhost", port: 5432, dnsAError: nil, dnsAAAAError: nil, connectionErrors: [NIOPosix.SingleConnectionFailure(target: [IPv6]localhost/::1:5432, error: connection reset (error set): Connection refused (errno: 61)), NIOPosix.SingleConnectionFailure(target: [IPv4]localhost/127.0.0.1:5432, error: connection reset (error set): Connection refused (errno: 61))]))

I have tried using a different port and trying to kill the server and postgres instances but nothing helps.

When trying to connect to my DB using Postico I get this message.

Invalid HTTP request, will close connection: invalid HTTP method (Vapor/HTTPServerRequestDecoder.swift:150)

I'm very new to this so any help will be appreciated. I can't find anything that helps online or when using chatGPT.

Thanks!

Hmm… can you curl from command line to confirm that requests are returning responses correctly?

This is including requests from curl?

The error message shows it's trying to connect to a database server on localhost port 5432 but there's nothing listening on it. How are you running your DB server?

This is not an error that you will see if you connect to a DB from Postico

This is the error I am getting in the swift console when I try connect to the db using Postico:

[ DEBUG ] Invalid HTTP request, will close connection: invalid HTTP method (Vapor/HTTPServerRequestDecoder.swift:150)

I was just relying on it starting up with the project. I think I managed to fix the Postico connection after your question about how I run my DB by running - brew services start postgresql. This is all local and I still have never deployed it - so that should be fun in the future.

Thanks for the cheeky rubber duck debugging :laughing:

Including curl yes. I have managed to fix the Postico connection and I will try to confirm the curl again and see if my client can finally connect - sorry need to run off to work right now.

Okay I can confirm it works now - looks like I needed to start the DB manually even though before it started up automatically with the project? - that might be my mis-remembrance though of how I started it up for the first time a few months back.

Im closing this. Thanks for taking the time to comment @vanvoorden @0xTim

1 Like