ETIMEDOUT - Unable to connect to Database

I run a Discord bot via discord.js. I can connect to my database perfectly fine via my laptop and view all the information. I’ve messed around with the configurations of the MariaDB database, but I just cannot get this to work. My bot hosted on a port on a separate VPS from the same provider who provides me the VPS for the Hestia panel is getting ETIMEDOUT when trying to connect to the database, no idea why? I’m assuming Hestia is somehow blocking the request or something on the VPS. I’ve tried disabling iptables and checked ufw is not on. I don’t know why I get this error, it’s unable to connect to the MariaDB server nor the FTP server, I used to use a DirectAdmin Reseller, I’ve kept the logic entirely the same and just modified the credentials and confirmed it. I used to host my database on a Pterodactyl instance with MariaDB so MariaDB should be compatible just fine with mysql2 package on NodeJS, no clue any ideas?

(Has been unable to connect to FTP nor Database, not even once via my other VPS hosting my Discord bot, but works fine connecting from my laptop, I’ve already set the bind address in configs to 0.0.0.0 to allow others to connect and not just localhost)

Error updating guild information: Error: connect ETIMEDOUT
at PoolConnection._handleTimeoutError (/home/container/node_modules/mysql2/lib/connection.js:205:17)
at listOnTimeout (node:internal/timers:573:17)
at process.processTimers (node:internal/timers:514:7) {
errorno: ‘ETIMEDOUT’,
code: ‘ETIMEDOUT’,
syscall: ‘connect’,
fatal: true
}

Show the output of these commands:

Note: replace YourDBUser with the actual DB user.

grep -ri bind-address /etc/mysql/
mysql -uroot -e 'select user,host from mysql.user where user = "YourDBUser";'
iptables -S
lsof -Pn +c0 -i:3306 -sTCP:LISTEN
1 Like

root@server:~# grep -ri bind-address /etc/mysql/
mysql -uroot -e ‘select user,host from mysql.user where user = “YourDBUser”;’
iptables -S
lsof -Pn +c0 -i:3306 -sTCP:LISTEN
/etc/mysql/mariadb.conf.d/50-server.cnf:bind-address = 0.0.0.0
/etc/mysql/mariadb.conf.d/60-galera.cnf:#bind-address = 0.0.0.0
-P INPUT DROP
-P FORWARD ACCEPT
-P OUTPUT ACCEPT
-N fail2ban-FTP
-N fail2ban-HESTIA
-N fail2ban-MAIL
-N fail2ban-RECIDIVE
-N fail2ban-SSH
-N fail2ban-WEB
-N hestia
-A INPUT -p tcp -m tcp --dport 8083 -j fail2ban-HESTIA
-A INPUT -p tcp -m multiport --dports 25,465,587,110,995,143,993 -j fail2ban-MAIL
-A INPUT -p tcp -m tcp --dport 21 -j fail2ban-FTP
-A INPUT -p tcp -m multiport --dports 80,443 -j fail2ban-WEB
-A INPUT -p tcp -m tcp --dport 22 -j fail2ban-SSH
-A INPUT -p tcp -m multiport --dports 1:65535 -j fail2ban-RECIDIVE
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -s 45.134.39.71/32 -j ACCEPT
-A INPUT -s 127.0.0.1/32 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 21,12000:12100 -j ACCEPT
-A INPUT -p udp -m udp --dport 53 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 53 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 25,465,587 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 110,995 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 143,993 -j ACCEPT
-A INPUT -p tcp -m tcp --dport 8083 -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A fail2ban-FTP -j RETURN
-A fail2ban-HESTIA -j RETURN
-A fail2ban-MAIL -j RETURN
-A fail2ban-RECIDIVE -s 202.39.239.109/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 170.64.222.223/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 186.151.240.74/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 95.79.112.59/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 62.171.137.67/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 20.204.165.90/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 14.63.196.175/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 43.159.59.118/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 64.227.161.111/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 118.193.78.167/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 43.156.162.193/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 159.223.45.100/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 43.128.111.199/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 162.62.127.194/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 152.228.131.33/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 61.177.172.179/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 104.250.34.226/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 165.232.165.149/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.24/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 62.204.41.158/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 180.101.88.196/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 181.55.188.218/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 180.101.88.205/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.34/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 103.115.24.11/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 179.43.180.108/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 104.250.50.179/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 79.110.62.145/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 158.220.112.173/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 105.174.43.194/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 173.12.223.153/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 103.19.190.92/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.107/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.112/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.113/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 183.81.169.238/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 61.177.172.136/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.27/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.31/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 61.177.172.140/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.150.246.42/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.76/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.118/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 180.101.88.197/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 61.177.172.160/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 43.153.68.27/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.56/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.29/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 218.92.0.22/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -s 201.81.240.66/32 -j REJECT --reject-with icmp-port-unreachable
-A fail2ban-RECIDIVE -j RETURN
-A fail2ban-SSH -j RETURN
-A fail2ban-WEB -j RETURN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME

Oh wait I need to replace DB User with my db user.

I miss the output of these two commands (remember to replace YourDBUser with the actual user):

mysql -uroot -e ‘select user,host from mysql.user where user = “YourDBUser”;’
lsof -Pn +c0 -i:3306 -sTCP:LISTEN

Regarding your iptables, you are not allowing connections to mysql port 3306, you should create a rule to allow connections to port 3306 from your external machine. I suppose your ip is 45.134.39.71 (you have a rule accepting all the connections) and that is the reason you can connect to your DB server.

2 Likes

I think I have just made the changes to the iptables and saved them. Thanks for your help in helping me find the issue. I’ll be testing it out right now. Here’s the additional info you requested just in case I messed something else up.

root@server:~# mysql -uroot -e ‘select user,host from mysql.user where user = “ash_bot”;’
±--------±----------+
| User | Host |
±--------±----------+
| ash_bot | % |
| ash_bot | localhost |
±--------±----------+
root@server:~#

root@server:~# lsof -Pn +c0 -i:3306 -sTCP:LISTEN
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mariadbd 2492198 mysql 58u IPv4 38305343 0t0 TCP *:3306 (LISTEN)
root@server:~#

1 Like

Yep the issue is fixed.

2 Likes

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.