Connection Refused

sometimes I got this error if I idle or open Metabase for the next day
Socket fail to connect to host:localhost, port:43003. Connection refused (Connection refused)
but if I resave the database configuration without editing I got normally.

i am running on a different server Metabase with database want to monitoring

Hi @herdikun
You are seeing this issue:
https://github.com/metabase/metabase/issues/6114 - upvote by clicking :+1: on the first post
The workaround is to setup the tunnel outside of Metabase and use that instead of the built-in tunnel:
https://www.metabase.com/docs/latest/administration-guide/01-managing-databases.html#what-if-the-built-in-ssh-tunnels-dont-fit-my-needs

this issue is still open and i didnt find the solution, what can i do for this issue?

@herdikun Correct the issue is still open. Like I wrote, you would have to setup a SSH tunnel outside of Metabase manually - that’s the workaround.

Sorry, i am a newbie. can you explain more about this
ssh -Nf -L input-port:internal-server-name:port-on-server username@bastion-host.domain.com
what is
input-port
internal-server-name = this is Metabase server?
port-on-server

@herdikun SSH is a fairly large subject by itself and there are many tutorials on the internet to learn more about it.
I don’t know your setup, so you might you need to search the internet for more information, since it is not specific to Metabase.

If you do something like this:
ssh -Nf -L 4321:mydb.company.internal:1234 username@bastion-host.domain.com
You would then connect in Metabase to localhost on port 4321, and the SSH tunnel would then connect to the bastion, which would then try to connect to mydb.company.internal on port 1234. If the database is on your bastion, then you would just use localhost instead of mydb.company.internal

Hi @flamber,

I am having a similar issue with my Metabase connection.
I have tried what you prescribed in:


but still getting the same connection error once I am idle for few minutes
I am running two remote servers, one is where I installed the docker metabase and the other server is where I have my MySQL database
I set up ssh connection as follows:
ssh -Nf -L “server-running-metabase-port:db-localhost:db-localhost-port username@db-server-ip”
Am I missing anything?

@tunde Make sure that you are not using the builtin SSH tunnel toggle in Metabase, since you’re handling it manually.

Hi @flamber,

When I tried that, am not able to connect at all. Attach image is my configuration

@tunde Post “Diagnostic Info” from Admin > Troubleshooting.
And post the non-redacted SSH command - you’re redacting too much. I don’t know if you have actually setup a tunnel on localhost listening on port 3306

Hi @flamber,

{
“browser-info”: {
“language”: “en-GB”,
“platform”: “Win32”,
“userAgent”: “Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36”,
“vendor”: “Google Inc.”
},
“system-info”: {
“file.encoding”: “UTF-8”,
“java.runtime.name”: “OpenJDK Runtime Environment”,
“java.runtime.version”: “11.0.7+10”,
“java.vendor”: “AdoptOpenJDK”,
“java.vendor.url”: “https://adoptopenjdk.net/”,
“java.version”: “11.0.7”,
“java.vm.name”: “OpenJDK 64-Bit Server VM”,
“java.vm.version”: “11.0.7+10”,
“os.name”: “Linux”,
“os.version”: “5.8.0-41-generic”,
“user.language”: “en”,
“user.timezone”: “GMT”
},
“metabase-info”: {
“databases”: [],
“hosting-env”: “unknown”,
“application-database”: “h2”,
“application-database-details”: {
“database”: {
“name”: “H2”,
“version”: “1.4.197 (2018-03-18)”
},
“jdbc-driver”: {
“name”: “H2 JDBC Driver”,
“version”: “1.4.197 (2018-03-18)”
}
},
“run-mode”: “prod”,
“version”: {
“date”: “2021-01-13”,
“tag”: “v0.37.6”,
“branch”: “release-x.37.x”,
“hash”: “344e5e0”
},
“settings”: {
“report-timezone”: “Europe/London”
}
}
}

Hi @flamber,

I have setup SSH tunnel to the localhost of my mysql database to port 3306

@tunde
Are you running Docker?
Or do you have anything blocking the Metabase java-process from accessing localhost:3306 ? You can use any other tool to test that - even just telnet:

telnet localhost 3306

Latest release is 0.37.8 and you should migrate away from H2 (unrelated to your current problem):
https://www.metabase.com/docs/latest/operations-guide/migrating-from-h2.html

Hi @flamber,
Yes, I am using Metabase docker, but my mysql database is not running on docker.
I am able to telnet localhost 3306 from the metabase server host to mysql database host.
Do I need special configuration if I am running metabase docker?

@tunde You have to remember that a docker container is a “server” by itself, so localhost inside of a container is the container itself - not the host.
https://stackoverflow.com/questions/28056522/access-host-database-from-a-docker-container

Hi @flamber,

Thanks for your help.
It is finally working now

Hi @tunde,
I am facing the same issue, Metabase server is running on docker, where DB is running on the host machine, on which docker is running.

Can you let me know what you did to resolve the issue?

@srinivas Try clicking the link I posted. You need to use host.docker.internal as the host address.
If you are not very familiar with Docker, then I would recommend using JAR instead.
https://www.metabase.com/docs/latest/operations-guide/installing-metabase.html

hi @flamber
I have used host.docker.internal as hostname while adding the database on Metabase but I am getting same error
image

@srinivas

  1. Post "Diagnostic Info" from Admin > Troubleshooting.
  2. Figure out what your Docker host IP address is and try that
  3. Make sure you don't have some firewalls blocking and that the process is actually listening on the interface and port.
  4. Otherwise use JAR.