Server Connect queries wont run for a Docker/Node/Postgres target - ECONREFUSED error

Hi All,

Not sure if this is a bug, or error in my config somewhere as i’d have thought others would have had issues if it was a proper bug.

I just created a new project (GIT clone) and set it up as local Docker/Node project.

Docker is working fine (can view it in Docker dashboard), database created in DB manager, DB connection is fine (can connect remotely through Navicat to the docker DB) but NO server connect queries will run and get this error:

{"status":"500","code":"ECONNREFUSED","message":"connect ECONNREFUSED 127.0.0.1:9906","stack":"Error: connect ECONNREFUSED 127.0.0.1:9906\n at TCPConnectWrap.afterConnect [as oncomplete] (net.js:1141:16)"}

Here is the target:

This is the Direct Connection details in DB manager:

Here is the Server Connect Connection:

For what it is worth, i can not change the port from 5432 to 9906 as it just reverts back to 5432 ( i’m guessing that is supposed to happen with how docker is configured.

Here is the Docker details from Dashboard:

Lastly, the strange thing is this. If i change targets to a local web server target (nodeJS) and use the running DOCKER details for a DB connection, i can connect to the DB and the server connect queries work??

If i am in local web server target, i created a DB connection using:


and it works fine?

Any ideas anyone?
It really seems like the port 5432 for the docker setting needs to be changed to 9906 but if i change it, it just reverts to 5432 on save.

In Docker it seems to be listening on IPv4 port 5432

but also has this when you inspect:

Sorry for the info overload. Just trying to provide clear picture.

bump.

Not sure if Wappler team saw this but i feel this might be a bug

If I see the error from the server connect query it looks like it is using the wrong connection. In the error message you see that it is trying to connect to post 9906, it should connect to port 5432.

Could you check the json file located at app/modules/connections/db.json. It should contain the connection settings for server connect.

The database is listening on port 5432 inside the docker image, it maps it to port 9906 for apps outside of the docker to connect to it.

HI @patrick,

Yes, i thought that it was strange and figured that inside Docker it was looking for port 5324.

Here is the file, when connected to my Docker target:

{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "postgres",
    "connection": {
      "host": "db",
      "port": 9906,
      "user": "db_user",
      "password": "xxxxxxxx",
      "database": "demo"
    }
  },
  "fileName": "db.json"
}

I went ahead and changed it to 5432 and it fixes the issue with my Docker target. It does seem to switch back to port 9906 though if i change targets or if i restart Wappler.

Thoughts?

Actually when you use Docker - all the needed database connections are generated automatically!
So you don’t have to edit anything manually.

You can check them as follows:

Should create a db connection called “db” that has both direct connection (for Wappler) and Server Connect conenction for SC, enabled:

The Wappler direct connection goes to:

and the Server Connect db connection to:

For remote targets - is pretty much the same only Wappler direct connection goes to the remote IP instead of the localhost.

Note that also for remote the Server Connect db connection still connects to the "local " for the server “db” database name. This is docker spesific.

Again all those docker db connections are automatically generated. For both local and remote targets.

If you do setup an additional db connection, or have a remote database server, you will have to always specify both a direct connection for Wappler and a separate Server Connect db connection from accessing the database from your server - if your database server is remote to both - then it will be usually the same connection settings.

Have you updated to the latest Wappler version? There were some fixes for the database connection in the last release.

Yes, I’m on 3.0.2.

And yes, I realise docker has created all the connections, but as you can see with the posts, they are not quite working.

I am able to work for now, only because I am using a local Dev target and connecting remotely into the db in the docker image.

Maybe you have an old connection file, under .wappler/targets:

image

it is auto updated when you reapply the targets settings in the project options, or when you just reapply your server connect db connection settings for that target

I will look into it

I have switched targets multiple times, restarted Wappler, killed all services on docker target etc but those same connection details remain and the docker target will not connect with the DB.

Looking at the DB.json file for the docker target, is it supposed to have these below details/port

?

Your help is much appreciated as everything has been set up fairly standard should work.

Cheers,
Phil

Did you reapply the target options, by just saving your project options again?

No I don’t think so, just used the docker options on the toolbar like ‘kill all services’ and ‘restart services’ and ‘deploy’ etc

Could you try to replicate the problem with a new project? And then provide us with the exact steps?

Well, I opened up the docker target and re-saved it like you said. It re-generated the DB connections like it now works.

When I inspect the DB file that Patrick mentioned it now has:

{
  "name": "db",
  "module": "dbconnector",
  "action": "connect",
  "options": {
    "client": "postgres",
    "connection": {
      "host": "db",
      "port": 5432,
      "user": "db_user",
      "password": "xxxxxxx",
      "database": "demo"
    }

Previously, in this same file it had port 9906.

I will keep an eye on it today and keep switching targets, reloading etc, to see if it continues to work.

If not, i will start a new project and see if i can replicate.

2 Likes